mirror of
https://github.com/neovim/neovim
synced 2025-07-19 10:41:48 +00:00
fix(treesitter): display fields for anonymous nodes in :InspectTree
(cherry picked from commit 9217e0d671
)
This commit is contained in:
committed by
Christian Clason
parent
5cad641848
commit
ab2d243fd0
@ -220,14 +220,13 @@ function TSTreeView:draw(bufnr)
|
|||||||
|
|
||||||
local text ---@type string
|
local text ---@type string
|
||||||
if item.node:named() then
|
if item.node:named() then
|
||||||
if item.field then
|
|
||||||
text = string.format('%s: (%s', item.field, item.node:type())
|
|
||||||
else
|
|
||||||
text = string.format('(%s', item.node:type())
|
text = string.format('(%s', item.node:type())
|
||||||
end
|
|
||||||
else
|
else
|
||||||
text = string.format('%q', item.node:type()):gsub('\n', 'n')
|
text = string.format('%q', item.node:type()):gsub('\n', 'n')
|
||||||
end
|
end
|
||||||
|
if item.field then
|
||||||
|
text = string.format('%s: %s', item.field, text)
|
||||||
|
end
|
||||||
|
|
||||||
local next = self:get(i + 1)
|
local next = self:get(i + 1)
|
||||||
if not next or next.depth <= item.depth then
|
if not next or next.depth <= item.depth then
|
||||||
|
@ -37,7 +37,7 @@ describe('vim.treesitter.inspect_tree', function()
|
|||||||
|
|
||||||
it('can toggle to show anonymous nodes', function()
|
it('can toggle to show anonymous nodes', function()
|
||||||
insert([[
|
insert([[
|
||||||
print()
|
print('hello')
|
||||||
]])
|
]])
|
||||||
|
|
||||||
exec_lua([[
|
exec_lua([[
|
||||||
@ -48,11 +48,15 @@ describe('vim.treesitter.inspect_tree', function()
|
|||||||
|
|
||||||
expect_tree [[
|
expect_tree [[
|
||||||
(chunk ; [0, 0] - [2, 0]
|
(chunk ; [0, 0] - [2, 0]
|
||||||
(function_call ; [0, 0] - [0, 7]
|
(function_call ; [0, 0] - [0, 14]
|
||||||
name: (identifier) ; [0, 0] - [0, 5]
|
name: (identifier) ; [0, 0] - [0, 5]
|
||||||
arguments: (arguments ; [0, 5] - [0, 7]
|
arguments: (arguments ; [0, 5] - [0, 14]
|
||||||
"(" ; [0, 5] - [0, 6]
|
"(" ; [0, 5] - [0, 6]
|
||||||
")"))) ; [0, 6] - [0, 7]
|
(string ; [0, 6] - [0, 13]
|
||||||
|
start: "'" ; [0, 6] - [0, 7]
|
||||||
|
content: (string_content) ; [0, 7] - [0, 12]
|
||||||
|
end: "'") ; [0, 12] - [0, 13]
|
||||||
|
")"))) ; [0, 13] - [0, 14]
|
||||||
]]
|
]]
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user