Reuse the source slice between layers

pull/1563/head^2
Blaž Hrastnik 3 years ago
parent 53d881f172
commit 5135fa37eb

@ -493,18 +493,19 @@ impl Syntax {
let mut cursor = ts_parser.cursors.pop().unwrap_or_else(QueryCursor::new); let mut cursor = ts_parser.cursors.pop().unwrap_or_else(QueryCursor::new);
// TODO: might need to set cursor range // TODO: might need to set cursor range
let source_slice = source.slice(..);
while let Some(layer_id) = queue.pop_front() { while let Some(layer_id) = queue.pop_front() {
// Re-parse the tree. // Re-parse the tree.
self.layers[layer_id].parse(ts_parser, source)?; self.layers[layer_id].parse(ts_parser, source)?;
let source = source.slice(..);
let layer = &self.layers[layer_id]; let layer = &self.layers[layer_id];
// Process injections. // Process injections.
let matches = cursor.matches( let matches = cursor.matches(
&layer.config.injections_query, &layer.config.injections_query,
layer.tree().root_node(), layer.tree().root_node(),
RopeProvider(source), RopeProvider(source_slice),
); );
let mut injections = Vec::new(); let mut injections = Vec::new();
for mat in matches { for mat in matches {
@ -512,12 +513,12 @@ impl Syntax {
&layer.config, &layer.config,
&layer.config.injections_query, &layer.config.injections_query,
&mat, &mat,
source, source_slice,
); );
// Explicitly remove this match so that none of its other captures will remain // Explicitly remove this match so that none of its other captures will remain
// in the stream of captures. // 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 // If a language is found with the given name, then add a new language layer
// to the highlighted document. // to the highlighted document.
@ -542,7 +543,7 @@ impl Syntax {
let matches = cursor.matches( let matches = cursor.matches(
combined_injections_query, combined_injections_query,
layer.tree().root_node(), layer.tree().root_node(),
RopeProvider(source), RopeProvider(source_slice),
); );
for mat in matches { for mat in matches {
let entry = &mut injections_by_pattern_index[mat.pattern_index]; let entry = &mut injections_by_pattern_index[mat.pattern_index];
@ -550,7 +551,7 @@ impl Syntax {
&layer.config, &layer.config,
combined_injections_query, combined_injections_query,
&mat, &mat,
source, source_slice,
); );
if language_name.is_some() { if language_name.is_some() {
entry.0 = language_name; entry.0 = language_name;

Loading…
Cancel
Save