mirror of
https://github.com/neovim/neovim
synced 2025-07-16 01:01:49 +00:00
fix(treesitter): lint top-level anonymous nodes
**Problem:** Top-level anonymous nodes are not being checked by the query linter **Solution:** Check them by adding them to the top-level query This commit also moves a table construction out of the match iterator so it is run less frequently.
This commit is contained in:
committed by
Christian Clason
parent
9d7711a732
commit
ba47b440fd
@ -65,7 +65,7 @@ local function normalize_opts(buf, opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local lint_query = [[;; query
|
local lint_query = [[;; query
|
||||||
(program [(named_node) (list) (grouping)] @toplevel)
|
(program [(named_node) (anonymous_node) (list) (grouping)] @toplevel)
|
||||||
(named_node
|
(named_node
|
||||||
name: _ @node.named)
|
name: _ @node.named)
|
||||||
(anonymous_node
|
(anonymous_node
|
||||||
@ -171,17 +171,17 @@ function M.lint(buf, opts)
|
|||||||
|
|
||||||
--- @type (table|nil)
|
--- @type (table|nil)
|
||||||
local parser_info = vim.F.npcall(vim.treesitter.language.inspect, lang)
|
local parser_info = vim.F.npcall(vim.treesitter.language.inspect, lang)
|
||||||
|
local lang_context = {
|
||||||
|
lang = lang,
|
||||||
|
parser_info = parser_info,
|
||||||
|
is_first_lang = i == 1,
|
||||||
|
}
|
||||||
|
|
||||||
local parser = vim.treesitter.get_parser(buf)
|
local parser = vim.treesitter.get_parser(buf)
|
||||||
parser:parse()
|
parser:parse()
|
||||||
parser:for_each_tree(function(tree, ltree)
|
parser:for_each_tree(function(tree, ltree)
|
||||||
if ltree:lang() == 'query' then
|
if ltree:lang() == 'query' then
|
||||||
for _, match, _ in query:iter_matches(tree:root(), buf, 0, -1, { all = true }) do
|
for _, match, _ in query:iter_matches(tree:root(), buf, 0, -1, { all = true }) do
|
||||||
local lang_context = {
|
|
||||||
lang = lang,
|
|
||||||
parser_info = parser_info,
|
|
||||||
is_first_lang = i == 1,
|
|
||||||
}
|
|
||||||
lint_match(buf, match, query, lang_context, diagnostics)
|
lint_match(buf, match, query, lang_context, diagnostics)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user