mirror of
https://github.com/neovim/neovim
synced 2025-07-16 01:01:49 +00:00
docs(treesitter): add disclaimer about needing to parse before get_node()
Problem: --- Misuse of `get_node()` is common: https://github.com/search?q=get_node_at_cursor+language%3Alua&type=code Solution: --- Add a note clarifying proper usage.
This commit is contained in:
committed by
Christian Clason
parent
d3e9cbedc7
commit
6c150e0b93
@ -599,6 +599,12 @@ get_captures_at_pos({bufnr}, {row}, {col})
|
||||
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|nil) Optional keyword arguments:
|
||||
• bufnr integer|nil Buffer number (nil or 0 for current
|
||||
|
@ -350,6 +350,14 @@ end
|
||||
|
||||
--- 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)
|
||||
--- ```
|
||||
---
|
||||
---@param opts table|nil Optional keyword arguments:
|
||||
--- - bufnr integer|nil Buffer number (nil or 0 for current buffer)
|
||||
--- - pos table|nil 0-indexed (row, col) tuple. Defaults to cursor position in the
|
||||
|
Reference in New Issue
Block a user