Skip to content

Commit 1d3cf8b

Browse files
committed
fix: vim.treesitter.is_ancestor no longer returns true for identical nodes
1 parent c1092f2 commit 1d3cf8b

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

lua/aerial/backends/treesitter/extensions.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ local default_methods = {
1818
get_parent = function(stack, match, node)
1919
for i = #stack, 1, -1 do
2020
local last_node = stack[i].node
21-
if vim.treesitter.is_ancestor(last_node, node) then
21+
if last_node == node or vim.treesitter.is_ancestor(last_node, node) then
2222
return stack[i].item, last_node, i
2323
else
2424
table.remove(stack, i)

lua/aerial/backends/treesitter/init.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,17 @@ M.fetch_symbols_sync = function(bufnr)
7979
local name_match = match.name or {}
8080
local selection_match = match.selection or {}
8181
local symbol_node = (match.symbol or match.type or {}).node
82+
if not symbol_node then
83+
goto continue
84+
end
8285
-- The location capture groups are optional. We default to the
8386
-- location of the @symbol capture
8487
local start_node = (match.start or {}).node or symbol_node
8588
local end_node = (match["end"] or {}).node or start_node
8689
local parent_item, parent_node, level = ext.get_parent(stack, match, symbol_node)
8790
-- Sometimes our queries will match the same node twice.
8891
-- Detect that (symbol_node == parent_node), and skip dupes.
89-
if not symbol_node or symbol_node == parent_node then
92+
if symbol_node == parent_node then
9093
goto continue
9194
end
9295
local kind = match.kind

tests/treesitter_spec.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ describe("treesitter", function()
2727
local filepath = "./tests/treesitter/" .. filename
2828
local basename = vim.fn.fnamemodify(filename, ":r")
2929
local symbols_file = "./tests/symbols/" .. basename .. ".json"
30-
it(filename, function()
31-
util.test_file_symbols("treesitter", filepath, symbols_file)
32-
end)
30+
if not vim.env.TS_TEST or vim.env.TS_TEST == basename then
31+
it(filename, function()
32+
util.test_file_symbols("treesitter", filepath, symbols_file)
33+
end)
34+
end
3335

34-
if filename == "markdown_test.md" then
36+
if filename == "markdown_test.md" and not vim.env.TS_TEST then
3537
it("<markdown backend> " .. filename, function()
3638
util.test_file_symbols("markdown", filepath, "./tests/symbols/markdown_backend.json")
3739
end)

0 commit comments

Comments
 (0)