on master help sign in
Reuse the source slice between layers
5135fa3Blaž Hrastnik
helix-core/src/syntax.rs+7−6
@@ -493,18 +493,19 @@ impl Syntax {
493 let mut cursor = ts_parser.cursors.pop().unwrap_or_else(QueryCursor::new);
493 let mut cursor = ts_parser.cursors.pop().unwrap_or_else(QueryCursor::new);
494 // TODO: might need to set cursor range
494 // TODO: might need to set cursor range
495
495
496+ let source_slice = source.slice(..);
497+
496 while let Some(layer_id) = queue.pop_front() {
498 while let Some(layer_id) = queue.pop_front() {
497 // Re-parse the tree.
499 // Re-parse the tree.
498 self.layers[layer_id].parse(ts_parser, source)?;
500 self.layers[layer_id].parse(ts_parser, source)?;
499
501
500− let source = source.slice(..);
501 let layer = &self.layers[layer_id];
502 let layer = &self.layers[layer_id];
502
503
503 // Process injections.
504 // Process injections.
504 let matches = cursor.matches(
505 let matches = cursor.matches(
505 &layer.config.injections_query,
506 &layer.config.injections_query,
506 layer.tree().root_node(),
507 layer.tree().root_node(),
507− RopeProvider(source),
508+ RopeProvider(source_slice),
508 );
509 );
509 let mut injections = Vec::new();
510 let mut injections = Vec::new();
510 for mat in matches {
511 for mat in matches {
@@ -512,12 +513,12 @@ impl Syntax {
512 &layer.config,
513 &layer.config,
513 &layer.config.injections_query,
514 &layer.config.injections_query,
514 &mat,
515 &mat,
515− source,
516+ source_slice,
516 );
517 );
517
518
518 // Explicitly remove this match so that none of its other captures will remain
519 // Explicitly remove this match so that none of its other captures will remain
519 // in the stream of captures.
520 // in the stream of captures.
520− mat.remove(); // TODO: is this still necessary?
521+ mat.remove();
521
522
522 // If a language is found with the given name, then add a new language layer
523 // If a language is found with the given name, then add a new language layer
523 // to the highlighted document.
524 // to the highlighted document.
@@ -542,7 +543,7 @@ impl Syntax {
542 let matches = cursor.matches(
543 let matches = cursor.matches(
543 combined_injections_query,
544 combined_injections_query,
544 layer.tree().root_node(),
545 layer.tree().root_node(),
545− RopeProvider(source),
546+ RopeProvider(source_slice),
546 );
547 );
547 for mat in matches {
548 for mat in matches {
548 let entry = &mut injections_by_pattern_index[mat.pattern_index];
549 let entry = &mut injections_by_pattern_index[mat.pattern_index];
@@ -550,7 +551,7 @@ impl Syntax {
550 &layer.config,
551 &layer.config,
551 combined_injections_query,
552 combined_injections_query,
552 &mat,
553 &mat,
553− source,
554+ source_slice,
554 );
555 );
555 if language_name.is_some() {
556 if language_name.is_some() {
556 entry.0 = language_name;
557 entry.0 = language_name;