aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/syntax.rs
diff options
context:
space:
mode:
authorMichael Davis2024-01-25 19:05:42 +0000
committerBlaž Hrastnik2024-01-28 09:13:33 +0000
commit5e0b3cc28b8ae6da1f41b47080a695c99bbc844a (patch)
tree9c20789f2d2aaa2ec691f3b3790c3eabf8b92955 /helix-core/src/syntax.rs
parent9978d421fe7237c74932c34263d91445728d65d1 (diff)
Use injection syntax trees for bracket matching
Previously we used the root syntax tree for bracket matching. We can use the new functionality in `Syntax` for finding the correct syntax tree for a given byte range though so we use the correct syntax tree within injections. This improves bracket matching behavior within HTML injections like script or style tags for example.
Diffstat (limited to 'helix-core/src/syntax.rs')
-rw-r--r--helix-core/src/syntax.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs
index a5a85c57..a403e7cc 100644
--- a/helix-core/src/syntax.rs
+++ b/helix-core/src/syntax.rs
@@ -1338,7 +1338,7 @@ impl Syntax {
result
}
- pub fn descendant_for_byte_range(&self, start: usize, end: usize) -> Option<Node<'_>> {
+ pub fn tree_for_byte_range(&self, start: usize, end: usize) -> &Tree {
let mut container_id = self.root;
for (layer_id, layer) in self.layers.iter() {
@@ -1349,8 +1349,11 @@ impl Syntax {
}
}
- self.layers[container_id]
- .tree()
+ self.layers[container_id].tree()
+ }
+
+ pub fn descendant_for_byte_range(&self, start: usize, end: usize) -> Option<Node<'_>> {
+ self.tree_for_byte_range(start, end)
.root_node()
.descendant_for_byte_range(start, end)
}