a list of captured
nodes
• pattern: the index of the matching pattern in the query
file
• predicate: list of strings containing the full directive
being called, e.g. `(node (#set! conceal "-"))` would get
the predicate `{ "#set!", "conceal", "-" }`
• {opts} (`table`) A table with the following fields:
• {force}? (`boolean`) Override an existing predicate of
the same name
• {all}? (`boolean`) Use the correct implementation of the
match table where capture IDs map to a list of nodes
instead of a single node. Defaults to true. This option
will be removed in a future release.
*vim.treesitter.query.add_predicate()*
add_predicate({name}, {handler}, {opts})
Adds a new predicate to be used in queries
Parameters: ~
• {name} (`string`) Name of the predicate, without leading #
• {handler} (`fun(match: table<integer,TSNode[]>, pattern: integer, source: integer|string, predicate: any[], metadata: vim.treesitter.query.TSMetadata): boolean?`)
• see |vim.treesitter.query.add_directive()| for argument
meanings
• {opts} (`table?`) A table with the following fields:
• {force}? (`boolean`) Override an existing predicate of
the same name
• {all}? (`boolean`) Use the correct implementation of the
match table where capture IDs map to a list of nodes
instead of a single node. Defaults to true. This option
will be removed in a future release.
edit({lang}) *vim.treesitter.query.edit()*
Opens a live editor to query the buffer you started from.
Can also be shown with *:EditQuery*.
If you move the cursor to a capture name ("@foo"), text matching the
capture is highlighted in the source buffer. The query editor is a scratch
buffer, use `:write` to save it. You can find example queries at
`$VIMRUNTIME/queries/`.
Parameters: ~
• {lang} (`string?`) language to open the query editor for. If omitted,
inferred from the current buffer's filetype.
get({lang}, {query_name}) *vim.treesitter.query.get()*
Returns the runtime query {query_name} for {lang}.
Parameters: ~
• {lang} (`string`) Language to use for the query
• {query_name} (`string`) Name of the query (e.g. "highlights")
Return: ~
(`vim.treesitter.Query?`) Parsed query. `nil` if no query files are
found. See |vim.treesitter.Query|.
*vim.treesitter.query.get_files()*
get_files({lang}, {query_name}, {is_included})
Gets the list of 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