==============================================================================
Lua module: vim.treesitter *lua-treesitter-core*
foldexpr({lnum}) *vim.treesitter.foldexpr()*
Returns the fold level for {lnum} in the current buffer. Can be set
directly to 'foldexpr': >lua
vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
<
Attributes: ~
Since: 0.9.0
Parameters: ~
• {lnum} (`integer?`) Line number to calculate fold level for
Return: ~
(`string`)
*vim.treesitter.get_captures_at_cursor()*
get_captures_at_cursor({winnr})
Returns a list of highlight capture names under the cursor
Parameters: ~
• {winnr} (`integer?`) |window-ID| or 0 for current window (default)
Return: ~
(`string[]`) List of capture names
*vim.treesitter.get_captures_at_pos()*
get_captures_at_pos({bufnr}, {row}, {col})
Returns a list of highlight captures at the given position
Each capture is represented by a table containing the capture name as a
string, the capture's language, a table of metadata (`priority`,
`conceal`, ...; empty if none are defined), and the id of the capture.
Parameters: ~
• {bufnr} (`integer`) Buffer number (0 for current buffer)
• {row} (`integer`) Position row
• {col} (`integer`) Position column
Return: ~
(`{capture: string, lang: string, metadata: vim.treesitter.query.TSMetadata, id: integer}[]`)
get_node({opts}) *vim.treesitter.get_node()*
Returns the smallest named node at the given position
NOTE: Calling this on an unparsed tree can yield an invalid node. If the
tree is not known to be parsed by, e.g., an active highlighter, parse the
tree first via >lua
vim.treesitter.get_parser(bufnr):parse(range)
<
Parameters: ~
• {opts} (`table?`) Optional keyword arguments:
• {bufnr} (`integer?`) Buffer number (nil or 0 for current
buffer)
• {pos} (`[integer, integer]?`) 0-indexed (row, col) tuple.
Defaults to cursor position in the current window. Required
if {bufnr} is not the current buffer
• {lang} (`string?`) Parser language. (default: from buffer
filetype)
• {ignore_injections} (`boolean?`) Ignore injected languages
(default true)
• {include_anonymous} (`boolean?`) Include anonymous nodes
(default false)
Return: ~
(`TSNode?`) Node at the given position
get_node_range({node_or_range}) *vim.treesitter.get_node_range()*
Returns the node's range or an unpacked range table
Parameters: ~
• {node_or_range} (`TSNode|Range4`) Node or table of positions
Return (multiple): ~
(`integer`) start_row
(`integer`) start_col
(`integer`) end_row
(`integer`) end_col
*vim.treesitter.get_node_text()*
get_node_text({node}, {source}, {opts})
Gets the text corresponding to a given node
Parameters: ~
• {node} (`TSNode`)
• {source} (`integer|string`) Buffer or string from which the {node} is
extracted
• {opts} (`table?`) Optional parameters.
• metadata (table) Metadata of a specific capture. This
would be set to `metadata[capture_id]` when using
|vim.treesitter.query.add_directive()|.
Return: ~
(`string`)
get_parser({bufnr}, {lang}, {opts}) *vim.treesitter.get_parser()*
Returns the parser for a specific buffer and attaches it to the buffer
If needed, this will create the parser.
If no parser can be created, an error is thrown. Set `opts.error = false`
to suppress