aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter/languagetree.lua
diff options
context:
space:
mode:
authorGregory Anders <8965202+gpanders@users.noreply.github.com>2022-12-08 09:22:57 -0700
committerGitHub <noreply@github.com>2022-12-08 09:22:57 -0700
commitd44699800cd0dbf14fb45476c13b6cc3c993b5c7 (patch)
tree378964d4739148359b3e78133fd8dc97d866cecb /runtime/lua/vim/treesitter/languagetree.lua
parent35767769036671d5ce562f53cae574f9c66e4bb2 (diff)
downloadrneovim-d44699800cd0dbf14fb45476c13b6cc3c993b5c7.tar.gz
rneovim-d44699800cd0dbf14fb45476c13b6cc3c993b5c7.tar.bz2
rneovim-d44699800cd0dbf14fb45476c13b6cc3c993b5c7.zip
feat(treesitter): add vim.treesitter.show_tree() (#21322)
Add a "show_tree" function to view a textual representation of the nodes in a language tree in a window. Moving the cursor in the window highlights the corresponding text in the source buffer, and moving the cursor in the source buffer highlights the corresponding nodes in the window.
Diffstat (limited to 'runtime/lua/vim/treesitter/languagetree.lua')
-rw-r--r--runtime/lua/vim/treesitter/languagetree.lua4
1 files changed, 3 insertions, 1 deletions
diff --git a/runtime/lua/vim/treesitter/languagetree.lua b/runtime/lua/vim/treesitter/languagetree.lua
index e9d70c4204..a1e96f8ef2 100644
--- a/runtime/lua/vim/treesitter/languagetree.lua
+++ b/runtime/lua/vim/treesitter/languagetree.lua
@@ -608,7 +608,9 @@ end
---@return userdata|nil Found |tsnode|
function LanguageTree:named_node_for_range(range, opts)
local tree = self:tree_for_range(range, opts)
- return tree:root():named_descendant_for_range(unpack(range))
+ if tree then
+ return tree:root():named_descendant_for_range(unpack(range))
+ end
end
--- Gets the appropriate language that contains {range}.