on master help sign in
fix: tree-sitter-scopes would infinitely loop
commit585e3ce83066bfe0235598660d32a6e171cc60cb authorBlaž Hrastnik <blaz@mxxn.io> dateThu 2 Sep 2021, 15:11 (5 years ago) parenta6108ba
1 file changed+8−3
helix-core/src/indent.rs+8−3
helix-core/src/indent.rs+8−3
@@ -316,8 +316,12 @@ pub fn suggested_indent_for_pos(
316316pub fn get_scopes(syntax: Option<&Syntax>, text: RopeSlice, pos: usize) -> Vec<&'static str> {
317317 let mut scopes = Vec::new();
318318 if let Some(syntax) = syntax {
319− let byte_start = text.char_to_byte(pos);
320− let node = match get_highest_syntax_node_at_bytepos(syntax, byte_start) {
319+ let pos = text.char_to_byte(pos);
320+ let mut node = match syntax
321+ .tree()
322+ .root_node()
323+ .descendant_for_byte_range(pos, pos)
324+ {
321325 Some(node) => node,
322326 None => return scopes,
323327 };
@@ -325,7 +329,8 @@ pub fn get_scopes(syntax: Option<&Syntax>, text: RopeSlice, pos: usize) -> Vec<&
325329 scopes.push(node.kind());
326330
327331 while let Some(parent) = node.parent() {
328− scopes.push(parent.kind())
332+ scopes.push(parent.kind());
333+ node = parent;
329334 }
330335 }
331336