fix(treesitter): remove more double recursion

Do not call `for_each_child` in functions that are already recursive.

(cherry picked from commit e76ae3d232)
This commit is contained in:
Lewis Russell 2023-09-12 11:38:31 +01:00 committed by github-actions[bot]
parent c7b316f71a
commit 5f8676c268
2 changed files with 36 additions and 27 deletions

View File

@ -800,6 +800,20 @@ function LanguageTree:_edit(
end
return true
end)
for _, child in pairs(self._children) do
child:_edit(
start_byte,
end_byte_old,
end_byte_new,
start_row,
start_col,
end_row_old,
end_col_old,
end_row_new,
end_col_new
)
end
end
---@package
@ -846,9 +860,7 @@ function LanguageTree:_on_bytes(
)
-- Edit trees together BEFORE emitting a bytes callback.
---@private
self:for_each_child(function(child)
child:_edit(
self:_edit(
start_byte,
start_byte + old_byte,
start_byte + new_byte,
@ -859,7 +871,6 @@ function LanguageTree:_on_bytes(
start_row + new_row,
new_end_col
)
end, true)
self:_do_callback(
'bytes',
@ -913,9 +924,9 @@ function LanguageTree:register_cbs(cbs, recursive)
end
if recursive then
self:for_each_child(function(child)
for _, child in pairs(self._children) do
child:register_cbs(cbs, true)
end)
end
end
end

View File

@ -102,18 +102,16 @@ function TSPlayground:new(bufnr, lang)
-- the root in the child tree to the {injections} table.
local root = parser:parse()[1]:root()
local injections = {} ---@type table<integer,table>
parser:for_each_child(function(child, lang_)
child:for_each_tree(function(tree)
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 = lang_,
lang = ltree:lang(),
root = r,
}
end
end)
end)
local nodes = traverse(root, 0, parser:lang(), injections, {})