Skip to content

Commit c271c90

Browse files
authored
fix(treesitter): simpler root node calculation (#396)
This eliminates the need to traverse up the tree to find its root, which can be costly for deep trees.
1 parent 7a7a78a commit c271c90

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

lua/nvim-surround/treesitter.lua

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,7 @@ end
3737
---@nodiscard
3838
M.get_root = function()
3939
local node = get_node()
40-
if node == nil then
41-
return nil
42-
end
43-
44-
while node:parent() ~= nil do
45-
node = node:parent()
46-
end
47-
48-
return node
40+
return node and node:tree():root()
4941
end
5042

5143
-- Gets the current smallest node at the cursor.

0 commit comments

Comments
 (0)