From 2e0230600448f2ac5a0811f1fe0faaad4bdde62c Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Mon, 17 Jun 2024 10:54:30 -0400 Subject: [PATCH] tree-sitter: Update parent links on reused injection layers When parsing injections, we skip adding a new layer if there is an existing layer covering the same range. When doing so we did not update the parent layer ID, so some layers could have `parent` layer IDs that pointed to a layer that no longer existed in the `layers` HopSlotMap which could cause a panic when using `A-o`. To fix this we update the `parent` pointer for both newly created injection layers and reused ones. --- helix-core/src/syntax.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 8fda29352812..93f618c09736 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -1363,13 +1363,14 @@ impl Syntax { let depth = layer.depth + 1; // TODO: can't inline this since matches borrows self.layers for (config, ranges) in injections { + let parent = Some(layer_id); let new_layer = LanguageLayer { tree: None, config, depth, ranges, flags: LayerUpdateFlags::empty(), - parent: Some(layer_id), + parent: None, }; // Find an identical existing layer @@ -1381,6 +1382,7 @@ impl Syntax { // ...or insert a new one. let layer_id = layer.unwrap_or_else(|| self.layers.insert(new_layer)); + self.layers[layer_id].parent = parent; queue.push_back(layer_id); }