aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/indent.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-09-02 06:11:27 +0000
committerBlaž Hrastnik2021-09-06 06:25:46 +0000
commit585e3ce83066bfe0235598660d32a6e171cc60cb (patch)
tree78f26c8f6a80f68406cfa6804271436549689ba0 /helix-core/src/indent.rs
parenta6108baec9455f223211b458e2328087e7fa3280 (diff)
fix: tree-sitter-scopes would infinitely loop
Diffstat (limited to 'helix-core/src/indent.rs')
-rw-r--r--helix-core/src/indent.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/helix-core/src/indent.rs b/helix-core/src/indent.rs
index f5f36aca..55802059 100644
--- a/helix-core/src/indent.rs
+++ b/helix-core/src/indent.rs
@@ -316,8 +316,12 @@ pub fn suggested_indent_for_pos(
pub fn get_scopes(syntax: Option<&Syntax>, text: RopeSlice, pos: usize) -> Vec<&'static str> {
let mut scopes = Vec::new();
if let Some(syntax) = syntax {
- let byte_start = text.char_to_byte(pos);
- let node = match get_highest_syntax_node_at_bytepos(syntax, byte_start) {
+ let pos = text.char_to_byte(pos);
+ let mut node = match syntax
+ .tree()
+ .root_node()
+ .descendant_for_byte_range(pos, pos)
+ {
Some(node) => node,
None => return scopes,
};
@@ -325,7 +329,8 @@ pub fn get_scopes(syntax: Option<&Syntax>, text: RopeSlice, pos: usize) -> Vec<&
scopes.push(node.kind());
while let Some(parent) = node.parent() {
- scopes.push(parent.kind())
+ scopes.push(parent.kind());
+ node = parent;
}
}