Skip to content

Commit

Permalink
fix(closest_test): uses new behavior of the iter_matches function (#97)
Browse files Browse the repository at this point in the history
See neovim breaking change PR: neovim/neovim#30193
Now iter_matches by default returns a list of node.
Iterates over all nodes with backward compatibility

Co-authored-by: Florent Cigolotti <[email protected]>
  • Loading branch information
florentcigolotti and Florent Cigolotti authored Oct 3, 2024
1 parent 5511788 commit 6aa8816
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions lua/dap-go-ts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,33 +89,37 @@ local function get_closest_test()

local test_query = vim.treesitter.query.parse(ft, tests_query)
assert(test_query, "could not parse test query")
for _, match, _ in test_query:iter_matches(root, 0, 0, stop_row) do
for _, match, _ in test_query:iter_matches(root, 0, 0, stop_row, { all = true }) do
local test_match = {}
for id, node in pairs(match) do
local capture = test_query.captures[id]
if capture == "testname" then
local name = vim.treesitter.get_node_text(node, 0)
test_match.name = name
end
if capture == "parent" then
test_match.node = node
for id, nodes in pairs(match) do
for _, node in ipairs(nodes) do
local capture = test_query.captures[id]
if capture == "testname" then
local name = vim.treesitter.get_node_text(node, 0)
test_match.name = name
end
if capture == "parent" then
test_match.node = node
end
end
end
table.insert(test_tree, test_match)
end

local subtest_query = vim.treesitter.query.parse(ft, subtests_query)
assert(subtest_query, "could not parse test query")
for _, match, _ in subtest_query:iter_matches(root, 0, 0, stop_row) do
for _, match, _ in subtest_query:iter_matches(root, 0, 0, stop_row, { all = true }) do
local test_match = {}
for id, node in pairs(match) do
local capture = subtest_query.captures[id]
if capture == "testname" then
local name = vim.treesitter.get_node_text(node, 0)
test_match.name = string.gsub(string.gsub(name, " ", "_"), '"', "")
end
if capture == "parent" then
test_match.node = node
for id, nodes in pairs(match) do
for _, node in ipairs(nodes) do
local capture = subtest_query.captures[id]
if capture == "testname" then
local name = vim.treesitter.get_node_text(node, 0)
test_match.name = string.gsub(string.gsub(name, " ", "_"), '"', "")
end
if capture == "parent" then
test_match.node = node
end
end
end
table.insert(test_tree, test_match)
Expand Down

0 comments on commit 6aa8816

Please sign in to comment.