display of the source language of each node, "o" to toggle
the query editor, and press <Enter> to jump to the node under the cursor
in the source buffer. Folding also works (try |zo|, |zc|, etc.).
Can also be shown with `:InspectTree`. *:InspectTree*
Attributes: ~
Since: 0.9.0
Parameters: ~
• {opts} (`table?`) Optional options table with the following possible
keys:
• lang (string|nil): The language of the source buffer. If
omitted, detect from the filetype of the source buffer.
• bufnr (integer|nil): Buffer to draw the tree into. If
omitted, a new buffer is created.
• winid (integer|nil): Window id to display the tree buffer
in. If omitted, a new window is created with {command}.
• command (string|nil): Vimscript command to create the
window. Default value is "60vnew". Only used when {winid} is
nil.
• title (string|fun(bufnr:integer):string|nil): Title of the
window. If a function, it accepts the buffer number of the
source buffer as its only argument and should return a
string.
is_ancestor({dest}, {source}) *vim.treesitter.is_ancestor()*
Determines whether a node is the ancestor of another
Parameters: ~
• {dest} (`TSNode`) Possible ancestor
• {source} (`TSNode`) Possible descendant
Return: ~
(`boolean`) True if {dest} is an ancestor of {source}
*vim.treesitter.is_in_node_range()*
is_in_node_range({node}, {line}, {col})
Determines whether (line, col) position is in node range
Parameters: ~
• {node} (`TSNode`) defining the range
• {line} (`integer`) Line (0-based)
• {col} (`integer`) Column (0-based)
Return: ~
(`boolean`) True if the position is in node range
node_contains({node}, {range}) *vim.treesitter.node_contains()*
Determines if a node contains a range
Parameters: ~
• {node} (`TSNode`)
• {range} (`table`)
Return: ~
(`boolean`) True if the {node} contains the {range}
start({bufnr}, {lang}) *vim.treesitter.start()*
Starts treesitter highlighting for a buffer
Can be used in an ftplugin or FileType autocommand.
Note: By default, disables regex syntax highlighting, which may be
required for some plugins. In this case, add `vim.bo.syntax = 'on'` after
the call to `start`.
Note: By default, the highlighter parses code asynchronously, using a
segment time of 3ms.
Example: >lua
vim.api.nvim_create_autocmd( 'FileType', { pattern = 'tex',
callback = function(args)
vim.treesitter.start(args.buf, 'latex')
vim.bo[args.buf].syntax = 'on' -- only if additional legacy syntax is needed
end
})
<
Parameters: ~
• {bufnr} (`integer?`) Buffer to be highlighted (default: current
buffer)
• {lang} (`string?`) Language of the parser (default: from buffer
filetype)
stop({bufnr}) *vim.treesitter.stop()*
Stops treesitter highlighting for a buffer
Parameters: ~
• {bufnr} (`integer?`) Buffer to stop highlighting (default: current
buffer)
==============================================================================
Lua module: vim.treesitter.language *treesitter-language*
add({lang}, {opts}) *vim.treesitter.language.add()*
Load parser with name {lang}
Parsers are searched in the `parser` runtime directory, or the provided
{path}. Can be used to check for available parsers before enabling
treesitter features, e.g., >lua
if