and a table of supertypes with their respective subtypes.
Parameters: ~
• {lang} (`string`) Language
Return: ~
(`TSLangInfo`)
register({lang}, {filetype}) *vim.treesitter.language.register()*
Register a parser named {lang} to be used for {filetype}(s).
Note: this adds or overrides the mapping for {filetype}, any existing
mappings from other filetypes to {lang} will be preserved.
Parameters: ~
• {lang} (`string`) Name of parser
• {filetype} (`string|string[]`) Filetype(s) to associate with lang
==============================================================================
Lua module: vim.treesitter.query *lua-treesitter-query*
This Lua |treesitter-query| interface allows you to create queries and use
them to parse text. See |vim.treesitter.query.parse()| for a working example.
*vim.treesitter.Query*
Parsed query, see |vim.treesitter.query.parse()|
Fields: ~
• {lang} (`string`) parser language name
• {captures} (`string[]`) list of (unique) capture names
defined in query
• {info} (`vim.treesitter.QueryInfo`) query context
(e.g. captures, predicates, directives)
• {has_conceal_line} (`boolean`) whether the query sets
conceal_lines metadata
• {has_combined_injections} (`boolean`) whether the query contains
combined injections
• {query} (`TSQuery`) userdata query object
• {iter_captures} (`fun(self: vim.treesitter.Query, node: TSNode, source: integer|string, start: integer?, stop: integer?, opts: table?): fun(end_line: integer?): integer, TSNode, vim.treesitter.query.TSMetadata, TSQueryMatch, TSTree`)
See |Query:iter_captures()|.
• {iter_matches} (`fun(self: vim.treesitter.Query, node: TSNode, source: integer|string, start: integer?, stop: integer?, opts: table?): fun(): integer, table<integer, TSNode[]>, vim.treesitter.query.TSMetadata, TSTree`)
See |Query:iter_matches()|.
*vim.treesitter.query.add_directive()*
add_directive({name}, {handler}, {opts})
Adds a new directive to be used in queries
Handlers can set match level data by setting directly on the metadata
object `metadata.key = value`. Additionally, handlers can set node level
data by using the capture id on the metadata table
`metadata[capture_id].key = value`
Parameters: ~
• {name} (`string`) Name of the directive, without leading #
• {handler} (`fun(match: table<integer,TSNode[]>, pattern: integer, source: integer|string, predicate: any[], metadata: vim.treesitter.query.TSMetadata)`)
• match: A table mapping capture IDs to 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