fixed tree-sitter iterators.

This commit is contained in:
Haoyuan (Bill) Xing 2025-04-16 21:44:39 -07:00
parent cf5c90c079
commit 437ddcbc87
Signed by: snmyj
GPG key ID: 59E2C2AAF8DCC4F0

View file

@ -89,8 +89,10 @@ function M.get_names_in_buffer(bufnr, line1, line2)
local passed = not range
local name
for id, node in pairs(match) do
for id, nodes in pairs(match) do
for _, node in ipairs(nodes) do
local row1, col1, row2, col2 = node:range()
local text = vim.api.nvim_buf_get_text(bufnr, row1, col1, row2, col2, {})[1]
if named_blocks_query.captures[id] == "block" and not passed then
@ -110,6 +112,7 @@ function M.get_names_in_buffer(bufnr, line1, line2)
table.insert(names, name)
end
end
end
return names
end
@ -130,7 +133,8 @@ function M.get_blocks_in_buffer(bufnr, line1, line2)
for _, match in unnamed_blocks_query:iter_matches(root, bufnr, 0, -1) do
local passed = not range
for id, node in pairs(match) do
for id, nodes in pairs(match) do
for _, node in ipairs(nodes) do
local row1, _, row2 = node:range()
if unnamed_blocks_query.captures[id] == "block" and not passed then
@ -141,6 +145,7 @@ function M.get_blocks_in_buffer(bufnr, line1, line2)
end
end
end
end
if passed then
table.insert(indexes, encountered)