commit 744674900f3cda497ea3c995e901788e33ae8fc0
parent 99e629481943929cbaa05bbf3e08e03e9a768fae
Author: Rodrigodd <rodrigobatsmoraes@hotmail.com>
Date: Wed, 4 Jun 2025 19:26:54 -0300
refactor(treesitter): avoid unnecessarily copying tree
node:tree() now already copies the tree before returning it, for memory
safety reasons.
Diffstat:
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua
@@ -979,8 +979,7 @@ function Query:iter_captures(node, source, start, stop, opts)
start, stop = value_or_node_range(start, stop, node)
- -- Copy the tree to ensure it is valid during the entire lifetime of the iterator
- local tree = node:tree():copy()
+ local tree = node:tree()
local cursor = vim._create_ts_querycursor(node, self.query, start, stop, opts)
-- For faster checks that a match is not in the cache.
@@ -1079,8 +1078,7 @@ function Query:iter_matches(node, source, start, stop, opts)
start, stop = value_or_node_range(start, stop, node)
- -- Copy the tree to ensure it is valid during the entire lifetime of the iterator
- local tree = node:tree():copy()
+ local tree = node:tree()
local cursor = vim._create_ts_querycursor(node, self.query, start, stop, opts)
local function iter()