on master help sign in
fix: tree-sitter-scopes would infinitely loop
585e3ceBlaž Hrastnik
helix-core/src/indent.rs+8−3
@@ -316,8 +316,12 @@ pub fn suggested_indent_for_pos(
316pub fn get_scopes(syntax: Option<&Syntax>, text: RopeSlice, pos: usize) -> Vec<&'static str> {
316pub fn get_scopes(syntax: Option<&Syntax>, text: RopeSlice, pos: usize) -> Vec<&'static str> {
317 let mut scopes = Vec::new();
317 let mut scopes = Vec::new();
318 if let Some(syntax) = syntax {
318 if let Some(syntax) = syntax {
319− let byte_start = text.char_to_byte(pos);
319+ let pos = text.char_to_byte(pos);
320− let node = match get_highest_syntax_node_at_bytepos(syntax, byte_start) {
320+ let mut node = match syntax
321+ .tree()
322+ .root_node()
323+ .descendant_for_byte_range(pos, pos)
324+ {
321 Some(node) => node,
325 Some(node) => node,
322 None => return scopes,
326 None => return scopes,
323 };
327 };
@@ -325,7 +329,8 @@ pub fn get_scopes(syntax: Option<&Syntax>, text: RopeSlice, pos: usize) -> Vec<&
325 scopes.push(node.kind());
329 scopes.push(node.kind());
326
330
327 while let Some(parent) = node.parent() {
331 while let Some(parent) = node.parent() {
328− scopes.push(parent.kind())
332+ scopes.push(parent.kind());
333+ node = parent;
329 }
334 }
330 }
335 }
331
336