Skip to content

Commit

Permalink
tree-sitter: Update parent links on reused injection layers (helix-ed…
Browse files Browse the repository at this point in the history
…itor#10978)

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.
  • Loading branch information
the-mikedavis authored and Schuyler Mortimer committed Jul 10, 2024
1 parent 0564285 commit 6d8bbf4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion helix-core/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down

0 comments on commit 6d8bbf4

Please sign in to comment.