on master help sign in
Reuse the source slice between layers
commit5135fa37eb11eb2c83cda12caddb5d9eb7cb1c61 authorBlaž Hrastnik <blaz@mxxn.io> dateMon 3 Jan 2022, 15:35 (5 years ago) parent53d881f
1 file changed+7−6
helix-core/src/syntax.rs+7−6
helix-core/src/syntax.rs+7−6
@@ -493,18 +493,19 @@ impl Syntax {
493493 let mut cursor = ts_parser.cursors.pop().unwrap_or_else(QueryCursor::new);
494494 // TODO: might need to set cursor range
495495
496+ let source_slice = source.slice(..);
497+
496498 while let Some(layer_id) = queue.pop_front() {
497499 // Re-parse the tree.
498500 self.layers[layer_id].parse(ts_parser, source)?;
499501
500− let source = source.slice(..);
501502 let layer = &self.layers[layer_id];
502503
503504 // Process injections.
504505 let matches = cursor.matches(
505506 &layer.config.injections_query,
506507 layer.tree().root_node(),
507− RopeProvider(source),
508+ RopeProvider(source_slice),
508509 );
509510 let mut injections = Vec::new();
510511 for mat in matches {
@@ -512,12 +513,12 @@ impl Syntax {
512513 &layer.config,
513514 &layer.config.injections_query,
514515 &mat,
515− source,
516+ source_slice,
516517 );
517518
518519 // Explicitly remove this match so that none of its other captures will remain
519520 // in the stream of captures.
520− mat.remove(); // TODO: is this still necessary?
521+ mat.remove();
521522
522523 // If a language is found with the given name, then add a new language layer
523524 // to the highlighted document.
@@ -542,7 +543,7 @@ impl Syntax {
542543 let matches = cursor.matches(
543544 combined_injections_query,
544545 layer.tree().root_node(),
545− RopeProvider(source),
546+ RopeProvider(source_slice),
546547 );
547548 for mat in matches {
548549 let entry = &mut injections_by_pattern_index[mat.pattern_index];
@@ -550,7 +551,7 @@ impl Syntax {
550551 &layer.config,
551552 combined_injections_query,
552553 &mat,
553− source,
554+ source_slice,
554555 );
555556 if language_name.is_some() {
556557 entry.0 = language_name;