From 6c150e0b9312ece13f13b7ff2e9743592bc9d431 Mon Sep 17 00:00:00 2001 From: L Lllvvuu Date: Wed, 27 Sep 2023 02:51:42 -0700 Subject: 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. --- runtime/lua/vim/treesitter.lua | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'runtime/lua') diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua index f863942d3b..e7a66c00b2 100644 --- a/runtime/lua/vim/treesitter.lua +++ b/runtime/lua/vim/treesitter.lua @@ -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 -- cgit