Skip to content

Commit 370514d

Browse files
committed
fix: prevent infinite loop when a node's parent is the node itself
1 parent ba6e234 commit 370514d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lua/hlchunk/utils/chunkHelper.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ local function get_chunk_range_by_treesitter(pos)
8282
return cursor_node:has_error() and chunkHelper.CHUNK_RANGE_RET.CHUNK_ERR or chunkHelper.CHUNK_RANGE_RET.OK,
8383
Scope(pos.bufnr, node_start, node_end)
8484
end
85-
cursor_node = cursor_node:parent()
85+
local parent_node = cursor_node:parent()
86+
if parent_node == cursor_node then
87+
break
88+
end
89+
cursor_node = parent_node
8690
end
8791
return chunkHelper.CHUNK_RANGE_RET.NO_CHUNK, Scope(pos.bufnr, -1, -1)
8892
end

0 commit comments

Comments
 (0)