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,26 +89,29 @@ function M.get_names_in_buffer(bufnr, line1, line2)
local passed = not range
local name
for id, node in pairs(match) do
local row1, col1, row2, col2 = node:range()
local text = vim.api.nvim_buf_get_text(bufnr, row1, col1, row2, col2, {})[1]
for id, nodes in pairs(match) do
for _, node in ipairs(nodes) do
local row1, col1, row2, col2 = node:range()
if named_blocks_query.captures[id] == "block" and not passed then
if single and line1 - 1 > row1 and line1 - 1 < row2 then
passed = true
elseif not single and line1 - 1 <= row1 and row2 <= line2 - 1 then
passed = true
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
if single and line1 - 1 > row1 and line1 - 1 < row2 then
passed = true
elseif not single and line1 - 1 <= row1 and row2 <= line2 - 1 then
passed = true
end
end
if named_blocks_query.captures[id] == "name" then
name = text
end
end
if named_blocks_query.captures[id] == "name" then
name = text
if passed then
table.insert(names, name)
end
end
if passed then
table.insert(names, name)
end
end
return names
end
@ -130,14 +133,16 @@ 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
local row1, _, row2 = node:range()
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
if single and line1 - 1 > row1 and line1 - 1 < row2 then
passed = true
elseif not single and line1 - 1 <= row1 and row2 <= line2 - 1 then
passed = true
if unnamed_blocks_query.captures[id] == "block" and not passed then
if single and line1 - 1 > row1 and line1 - 1 < row2 then
passed = true
elseif not single and line1 - 1 <= row1 and row2 <= line2 - 1 then
passed = true
end
end
end
end