diff options
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/doc/news.txt | 2 | ||||
| -rw-r--r-- | runtime/doc/treesitter.txt | 2 | ||||
| -rw-r--r-- | runtime/lua/vim/treesitter.lua | 6 |
3 files changed, 10 insertions, 0 deletions
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index 2ddda72ae8..745e84d02e 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -167,6 +167,8 @@ TERMINAL TREESITTER • |LanguageTree:node_for_range()| gets anonymous and named nodes for a range +• |vim.treesitter.get_node()| now takes an option `include_anonymous`, default + false, which allows it to return anonymous nodes as well as named nodes. TUI diff --git a/runtime/doc/treesitter.txt b/runtime/doc/treesitter.txt index cd8a4d8ec5..97f77c9e31 100644 --- a/runtime/doc/treesitter.txt +++ b/runtime/doc/treesitter.txt @@ -773,6 +773,8 @@ get_node({opts}) *vim.treesitter.get_node()* filetype) • {ignore_injections} (`boolean?`) Ignore injected languages (default true) + • {include_anonymous} (`boolean?`) Include anonymous nodes + (default false) Return: ~ (`TSNode?`) Node at the given position diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua index e36aacfd94..4629203138 100644 --- a/runtime/lua/vim/treesitter.lua +++ b/runtime/lua/vim/treesitter.lua @@ -342,6 +342,9 @@ end --- --- Ignore injected languages (default true) --- @field ignore_injections boolean? +--- +--- Include anonymous nodes (default false) +--- @field include_anonymous boolean? --- Returns the smallest named node at the given position --- @@ -388,6 +391,9 @@ function M.get_node(opts) return end + if opts.include_anonymous then + return root_lang_tree:node_for_range(ts_range, opts) + end return root_lang_tree:named_node_for_range(ts_range, opts) end |