From 1af55bfcf21b9bc7594b9c5ee0c2f60cbb887654 Mon Sep 17 00:00:00 2001 From: Riley Bruins Date: Sun, 28 Jul 2024 13:30:33 -0700 Subject: feat(treesitter): allow get_node to return anonymous nodes Adds a new field `include_anonymous` to the `get_node` options to allow anonymous nodes to be returned. --- runtime/lua/vim/treesitter.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'runtime/lua/vim') 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 -- cgit