files used to make up a query
Parameters: ~
• {lang} (`string`) Language to get query for
• {query_name} (`string`) Name of the query to load (e.g.,
"highlights")
• {is_included} (`boolean?`) Internal parameter, most of the time left
as `nil`
Return: ~
(`string[]`) query_files List of files to load for given query and
language
lint({buf}, {opts}) *vim.treesitter.query.lint()*
Lint treesitter queries using installed parser, or clear lint errors.
Use |treesitter-parsers| in runtimepath to check the query file in {buf}
for errors:
• verify that used nodes are valid identifiers in the grammar.
• verify that predicates and directives are valid.
• verify that top-level s-expressions are valid.
The found diagnostics are reported using |diagnostic-api|. By default, the
parser used for verification is determined by the containing folder of the
query file, e.g., if the path ends in `/lua/highlights.scm`, the parser
for the `lua` language will be used.
Parameters: ~
• {buf} (`integer`) Buffer handle
• {opts} (`table?`) Optional keyword arguments:
• {langs}? (`string|string[]`) Language(s) to use for checking
the query. If multiple languages are specified, queries are
validated for all of them
• {clear} (`boolean`) Just clear current lint errors
list_directives() *vim.treesitter.query.list_directives()*
Lists the currently available directives to use in queries.
Return: ~
(`string[]`) Supported directives.
list_predicates() *vim.treesitter.query.list_predicates()*
Lists the currently available predicates to use in queries.
Return: ~
(`string[]`) Supported predicates.
omnifunc({findstart}, {base}) *vim.treesitter.query.omnifunc()*
Omnifunc for completing node names and predicates in treesitter queries.
Use via >lua
vim.bo.omnifunc = 'v:lua.vim.treesitter.query.omnifunc'
<
Parameters: ~
• {findstart} (`0|1`)
• {base} (`string`)
parse({lang}, {query}) *vim.treesitter.query.parse()*
Parses a {query} string and returns a `Query` object
(|lua-treesitter-query|), which can be used to search the tree for the
query patterns (via |Query:iter_captures()|, |Query:iter_matches()|), or
inspect/modify the query via these fields:
• `captures`: a list of unique capture names defined in the query (alias:
`info.captures`).
• `info.patterns`: information about predicates.
• `query`: the underlying |TSQuery| which can be used to disable patterns
or captures.
Example: >lua
local query = vim.treesitter.query.parse('vimdoc', [[
; query
((h1) @str
(#trim! @str 1 1 1 1))
]])
local tree = vim.treesitter.get_parser():parse()[1]
for id, node, metadata in query:iter_captures(tree:root(), 0) do
-- Print the node name and source text.
vim.print({node:type(), vim.treesitter.get_node_text(node, vim.api.nvim_get_current_buf())})
end
<
Parameters: ~
• {lang} (`string`) Language to use for the query
• {query} (`string`) Query text, in s-expr syntax
Return: ~
(`vim.treesitter.Query`) Parsed query . See |vim.treesitter.Query|.
See also: ~
• |vim.treesitter.query.get()|
*Query:iter_captures()*
Query:iter_captures({node}, {source}, {start}, {stop}, {opts})
Iterates over all captures from all matches in {node}.
{source} is required if the query contains predicates; then the caller
must ensure to use a freshly parsed tree consistent with the current text
of the buffer (if relevant). {start} and {stop} can be used to limit