@@ -65,6 +65,32 @@ impl LanguageLayer {
65// -- refactored from tree-sitter-highlight to be able to retain state
65// -- refactored from tree-sitter-highlight to be able to retain state
66// TODO: add seek() to iter
66// TODO: add seek() to iter
68+// problem: any time a layer is updated it must update it's injections on the parent (potentially
69+// removing some from use)
70+// can't modify to vec and exist in it at the same time since that would violate borrows
71+// maybe we can do with an arena
72+// maybe just caching on the top layer and nevermind the injections for now?
75+// layers: Vec<Box<Layer>> to prevent memory moves when vec is modified
77+// injections tracked by marker:
78+// if marker areas match it's fine and update
79+// if not found add new layer
80+// if length 0 then area got removed, clean up the layer
83+// if range.len = 0 then remove the layer
84+// for change in changes { tree.edit(change) }
85+// tree = parser.parse(.., tree, ..)
86+// calculate affected range and update injections
88+// look for existing injections
89+// if present, range = (first injection start, last injection end)
91+// For now cheat and just throw out non-root layers if they exist. This should still improve
92+// parsing in majority of cases.
68use std::sync::atomic::{AtomicUsize, Ordering};
94use std::sync::atomic::{AtomicUsize, Ordering};
69use std::{iter, mem, ops, str, usize};
95use std::{iter, mem, ops, str, usize};
70use tree_sitter::{
96use tree_sitter::{
@@ -73,8 +99,6 @@ use tree_sitter::{
75const CANCELLATION_CHECK_INTERVAL: usize = 100;
101const CANCELLATION_CHECK_INTERVAL: usize = 100;
76−const BUFFER_HTML_RESERVE_CAPACITY: usize = 10 * 1024;
77−const BUFFER_LINES_RESERVE_CAPACITY: usize = 1000;
79/// Indicates which highlight should be applied to a region of source code.
103/// Indicates which highlight should be applied to a region of source code.
80#[derive(Copy, Clone, Debug, PartialEq, Eq)]
104#[derive(Copy, Clone, Debug, PartialEq, Eq)]
@@ -207,7 +231,7 @@ impl Highlighter {
207 cancellation_flag,
231 cancellation_flag,
208 highlighter: self,
232 highlighter: self,
209 iter_count: 0,
233 iter_count: 0,
210− layers: layers,
234+ layers,
211 next_event: None,
235 next_event: None,
212 last_highlight_range: None,
236 last_highlight_range: None,
@@ -405,7 +429,7 @@ impl<'a> HighlightIterLayer<'a> {
405 .parse(source, None)
429 .parse(source, None)
406 .ok_or(Error::Cancelled)?;
430 .ok_or(Error::Cancelled)?;
407 unsafe { highlighter.parser.set_cancellation_flag(None) };
431 unsafe { highlighter.parser.set_cancellation_flag(None) };
408− let mut cursor = highlighter.cursors.pop().unwrap_or(QueryCursor::new());
432+ let mut cursor = highlighter.cursors.pop().unwrap_or_else(QueryCursor::new);
410 // Process combined injections.
434 // Process combined injections.
411 if let Some(combined_injections_query) = &config.combined_injections_query {
435 if let Some(combined_injections_query) = &config.combined_injections_query {
@@ -642,7 +666,7 @@ where
644 if i > 0 {
668 if i > 0 {
645− &self.layers[0..(i + 1)].rotate_left(1);
669+ self.layers[0..(i + 1)].rotate_left(1);
@@ -802,12 +826,9 @@ where
802 local_defs: Vec::new(),
826 local_defs: Vec::new(),
804 for prop in layer.config.query.property_settings(match_.pattern_index) {
828 for prop in layer.config.query.property_settings(match_.pattern_index) {
805− match prop.key.as_ref() {
806− "local.scope-inherits" => {
829+ if let "local.scope-inherits" = prop.key.as_ref() {
807− scope.inherits =
830+ scope.inherits =
808− prop.value.as_ref().map_or(true, |r| r.as_ref() == "true");
831+ prop.value.as_ref().map_or(true, |r| r.as_ref() == "true");
813 layer.scope_stack.push(scope);
834 layer.scope_stack.push(scope);