aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2022-01-03 06:35:05 +0000
committerBlaž Hrastnik2022-01-23 07:00:24 +0000
commit5135fa37eb11eb2c83cda12caddb5d9eb7cb1c61 (patch)
tree683f540a7f47e5901ae1a34c7e06ea1f00062e85 /helix-core/src
parent53d881f17229e1fcda4f1e139258059b85e6beeb (diff)
Reuse the source slice between layers
Diffstat (limited to 'helix-core/src')
-rw-r--r--helix-core/src/syntax.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs
index 8a973569..6e128f0b 100644
--- a/helix-core/src/syntax.rs
+++ b/helix-core/src/syntax.rs
@@ -493,18 +493,19 @@ impl Syntax {
let mut cursor = ts_parser.cursors.pop().unwrap_or_else(QueryCursor::new);
// TODO: might need to set cursor range
+ let source_slice = source.slice(..);
+
while let Some(layer_id) = queue.pop_front() {
// Re-parse the tree.
self.layers[layer_id].parse(ts_parser, source)?;
- let source = source.slice(..);
let layer = &self.layers[layer_id];
// Process injections.
let matches = cursor.matches(
&layer.config.injections_query,
layer.tree().root_node(),
- RopeProvider(source),
+ RopeProvider(source_slice),
);
let mut injections = Vec::new();
for mat in matches {
@@ -512,12 +513,12 @@ impl Syntax {
&layer.config,
&layer.config.injections_query,
&mat,
- source,
+ source_slice,
);
// Explicitly remove this match so that none of its other captures will remain
// in the stream of captures.
- mat.remove(); // TODO: is this still necessary?
+ mat.remove();
// If a language is found with the given name, then add a new language layer
// to the highlighted document.
@@ -542,7 +543,7 @@ impl Syntax {
let matches = cursor.matches(
combined_injections_query,
layer.tree().root_node(),
- RopeProvider(source),
+ RopeProvider(source_slice),
);
for mat in matches {
let entry = &mut injections_by_pattern_index[mat.pattern_index];
@@ -550,7 +551,7 @@ impl Syntax {
&layer.config,
combined_injections_query,
&mat,
- source,
+ source_slice,
);
if language_name.is_some() {
entry.0 = language_name;