a
component of the |vim.treesitter.Query| for language feature support. See
|treesitter-query| for more about queries or
|vim.treesitter.query.parse()| for an example of how to obtain a query
object.
Fields: ~
• {disable_capture} (`fun(self: TSQuery, capture_name: string)`) See
|TSQuery:disable_capture()|.
• {disable_pattern} (`fun(self: TSQuery, pattern_index: integer)`) See
|TSQuery:disable_pattern()|.
TSQuery:disable_capture({capture_name}) *TSQuery:disable_capture()*
Disable a specific capture in this query; once disabled the capture cannot
be re-enabled. {capture_name} should not include a leading "@".
Example: To disable the `@variable.parameter` capture from the vimdoc
highlights query: >lua
local query = vim.treesitter.query.get('vimdoc', 'highlights')
query.query:disable_capture("variable.parameter")
vim.treesitter.get_parser():parse()
<
Parameters: ~
• {capture_name} (`string`)
TSQuery:disable_pattern({pattern_index}) *TSQuery:disable_pattern()*
Disable a specific pattern in this query; once disabled the pattern cannot
be re-enabled. The {pattern_index} for a particular match can be obtained
with |:Inspect!|, or by reading the source of the query (i.e. from
|vim.treesitter.query.get_files()|).
Example: To disable `|` links in vimdoc but keep other `@markup.link`s
highlighted: >lua
local link_pattern = 9 -- from :Inspect!
local query = vim.treesitter.query.get('vimdoc', 'highlights')
query.query:disable_pattern(link_pattern)
local tree = vim.treesitter.get_parser():parse()[1]
<
Parameters: ~
• {pattern_index} (`integer`)
==============================================================================
Lua module: vim.treesitter.languagetree *treesitter-languagetree*
A *LanguageTree* contains a tree of parsers: the root treesitter parser for
{lang} and any "injected" language parsers, which themselves may inject other
languages, recursively. For example a Lua buffer containing some Vimscript
commands needs multiple parsers to fully understand its contents.
To create a LanguageTree (parser object) for a given buffer and language, use: >lua
local parser = vim.treesitter.get_parser(bufnr, lang)
<
(where `bufnr=0` means current buffer). `lang` defaults to 'filetype'. Note:
currently the parser is retained for the lifetime of a buffer but this may
change; a plugin should keep a reference to the parser object if it wants
incremental updates.
Whenever you need to access the current syntax tree, parse the buffer: >lua
local tree = parser:parse({ start_row, end_row })
<
This returns a table of immutable |treesitter-tree| objects representing the
current state of the buffer. When the plugin wants to access the state after a
(possible) edit it must call `parse()` again. If the buffer wasn't edited, the
same tree will be returned again without extra work. If the buffer was parsed
before, incremental parsing will be done of the changed parts.
Note: To use the parser directly inside a |nvim_buf_attach()| Lua callback,
you must call |vim.treesitter.get_parser()| before you register your callback.
But preferably parsing shouldn't be done directly in the change callback
anyway as they will be very frequent. Rather a plugin that does any kind of
analysis on a tree should use a timer to throttle too frequent updates.
LanguageTree:children() *LanguageTree:children()*
Returns a map of language to child tree.
Return: ~
(`table<string,vim.treesitter.LanguageTree>`)
LanguageTree:contains({range}) *LanguageTree:contains()*
Determines whether {range} is contained in the |LanguageTree|.
Parameters: ~
• {range} (`table`) A table with the following fields:
• {[1]} (`integer`) start row