fix(treesitter): remove more double recursion

Do not call `for_each_child` in functions that are already recursive.
This commit is contained in:
Lewis Russell
2023-09-12 11:38:31 +01:00
committed by Lewis Russell
parent 1c4a93b591
commit 7a76fb8547
2 changed files with 36 additions and 27 deletions

View File

@@ -101,17 +101,15 @@ function TSTreeView:new(bufnr, lang)
-- the root in the child tree to the {injections} table.
local root = parser:parse(true)[1]:root()
local injections = {} ---@type table<integer,table>
parser:for_each_child(function(child, lang_)
child:for_each_tree(function(tree)
local r = tree:root()
local node = root:named_descendant_for_range(r:range())
if node then
injections[node:id()] = {
lang = lang_,
root = r,
}
end
end)
parser:for_each_tree(function(tree, ltree)
local r = tree:root()
local node = root:named_descendant_for_range(r:range())
if node then
injections[node:id()] = {
lang = ltree:lang(),
root = r,
}
end
end)
local nodes = traverse(root, 0, parser:lang(), injections, {})