mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
feat(treesitter): show which nodes are missing in InspectTree
Now `:InspectTree` will show missing nodes as e.g. `(MISSING identifier)` or `(MISSING ";")` rather than just `(identifier)` or `";"`. This is doable because the `MISSING` keyword is now valid query syntax. Co-authored-by: Christian Clason <c.clason@uni-graz.at>
This commit is contained in:
parent
d769c340b9
commit
09f9f0a946
@ -381,6 +381,7 @@ TREESITTER
|
|||||||
queries in addition to overriding.
|
queries in addition to overriding.
|
||||||
• |LanguageTree:is_valid()| now accepts a range parameter to narrow the scope
|
• |LanguageTree:is_valid()| now accepts a range parameter to narrow the scope
|
||||||
of the validity check.
|
of the validity check.
|
||||||
|
• |:InspectTree| now shows which nodes are missing.
|
||||||
|
|
||||||
TUI
|
TUI
|
||||||
|
|
||||||
|
@ -224,9 +224,12 @@ function TSTreeView:draw(bufnr)
|
|||||||
|
|
||||||
local text ---@type string
|
local text ---@type string
|
||||||
if item.node:named() then
|
if item.node:named() then
|
||||||
text = string.format('(%s', item.node:type())
|
text = string.format('(%s%s', item.node:missing() and 'MISSING ' or '', item.node:type())
|
||||||
else
|
else
|
||||||
text = string.format('%q', item.node:type()):gsub('\n', 'n')
|
text = string.format('%q', item.node:type()):gsub('\n', 'n')
|
||||||
|
if item.node:missing() then
|
||||||
|
text = string.format('(MISSING %s)', text)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if item.field then
|
if item.field then
|
||||||
text = string.format('%s: %s', item.field, text)
|
text = string.format('%s: %s', item.field, text)
|
||||||
|
@ -178,4 +178,63 @@ describe('vim.treesitter.inspect_tree', function()
|
|||||||
-- close source buffer window and all remaining tree windows
|
-- close source buffer window and all remaining tree windows
|
||||||
n.expect_exit(n.command, 'quit')
|
n.expect_exit(n.command, 'quit')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('shows which nodes are missing', function()
|
||||||
|
insert([[
|
||||||
|
int main() {
|
||||||
|
if (a.) {
|
||||||
|
// ^ MISSING field_identifier here
|
||||||
|
if (1) d()
|
||||||
|
// ^ MISSING ";" here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]])
|
||||||
|
|
||||||
|
exec_lua(function()
|
||||||
|
vim.treesitter.start(0, 'c')
|
||||||
|
vim.treesitter.inspect_tree()
|
||||||
|
end)
|
||||||
|
feed('a')
|
||||||
|
|
||||||
|
expect_tree [[
|
||||||
|
(translation_unit ; [0, 0] - [8, 0]
|
||||||
|
(function_definition ; [0, 0] - [6, 1]
|
||||||
|
type: (primitive_type) ; [0, 0] - [0, 3]
|
||||||
|
declarator: (function_declarator ; [0, 4] - [0, 10]
|
||||||
|
declarator: (identifier) ; [0, 4] - [0, 8]
|
||||||
|
parameters: (parameter_list ; [0, 8] - [0, 10]
|
||||||
|
"(" ; [0, 8] - [0, 9]
|
||||||
|
")")) ; [0, 9] - [0, 10]
|
||||||
|
body: (compound_statement ; [0, 11] - [6, 1]
|
||||||
|
"{" ; [0, 11] - [0, 12]
|
||||||
|
(if_statement ; [1, 4] - [5, 5]
|
||||||
|
"if" ; [1, 4] - [1, 6]
|
||||||
|
condition: (parenthesized_expression ; [1, 7] - [1, 11]
|
||||||
|
"(" ; [1, 7] - [1, 8]
|
||||||
|
(field_expression ; [1, 8] - [1, 10]
|
||||||
|
argument: (identifier) ; [1, 8] - [1, 9]
|
||||||
|
operator: "." ; [1, 9] - [1, 10]
|
||||||
|
field: (MISSING field_identifier)) ; [1, 10] - [1, 10]
|
||||||
|
")") ; [1, 10] - [1, 11]
|
||||||
|
consequence: (compound_statement ; [1, 12] - [5, 5]
|
||||||
|
"{" ; [1, 12] - [1, 13]
|
||||||
|
(comment) ; [2, 4] - [2, 41]
|
||||||
|
(if_statement ; [3, 8] - [4, 36]
|
||||||
|
"if" ; [3, 8] - [3, 10]
|
||||||
|
condition: (parenthesized_expression ; [3, 11] - [3, 14]
|
||||||
|
"(" ; [3, 11] - [3, 12]
|
||||||
|
(number_literal) ; [3, 12] - [3, 13]
|
||||||
|
")") ; [3, 13] - [3, 14]
|
||||||
|
consequence: (expression_statement ; [3, 15] - [4, 36]
|
||||||
|
(call_expression ; [3, 15] - [3, 18]
|
||||||
|
function: (identifier) ; [3, 15] - [3, 16]
|
||||||
|
arguments: (argument_list ; [3, 16] - [3, 18]
|
||||||
|
"(" ; [3, 16] - [3, 17]
|
||||||
|
")")) ; [3, 17] - [3, 18]
|
||||||
|
(comment) ; [4, 8] - [4, 36]
|
||||||
|
(MISSING ";"))) ; [4, 36] - [4, 36]
|
||||||
|
"}")) ; [5, 4] - [5, 5]
|
||||||
|
"}"))) ; [6, 0] - [6, 1]
|
||||||
|
]]
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user