aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter.lua
diff options
context:
space:
mode:
authorQuentin Rasmont <qrasmont@gmail.com>2022-04-22 21:50:52 +0200
committerbfredl <bjorn.linse@gmail.com>2022-08-25 18:01:14 +0200
commit3aba4ba37859e4407eff2bb3f4d99c44b108ed79 (patch)
treeb64398bebd9f5f2860249056eef84016e250ca58 /runtime/lua/vim/treesitter.lua
parent22f920030214c0023525c59daf763441baddba1a (diff)
downloadrneovim-3aba4ba37859e4407eff2bb3f4d99c44b108ed79.tar.gz
rneovim-3aba4ba37859e4407eff2bb3f4d99c44b108ed79.tar.bz2
rneovim-3aba4ba37859e4407eff2bb3f4d99c44b108ed79.zip
feat(treesitter): upstream is_parent()
Util from the nvim-treesitter project. Renamed is_parent to is_ancestor for clarity.
Diffstat (limited to 'runtime/lua/vim/treesitter.lua')
-rw-r--r--runtime/lua/vim/treesitter.lua23
1 files changed, 23 insertions, 0 deletions
diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua
index 70f2c425ed..37ab59b259 100644
--- a/runtime/lua/vim/treesitter.lua
+++ b/runtime/lua/vim/treesitter.lua
@@ -118,4 +118,27 @@ function M.get_string_parser(str, lang, opts)
return LanguageTree.new(str, lang, opts)
end
+--- Determines whether a node is the ancestor of another
+---
+---@param dest table the possible ancestor
+---@param source table the possible descendant node
+---
+---@returns (boolean) True if dest is an ancestor of source
+function M.is_ancestor(dest, source)
+ if not (dest and source) then
+ return false
+ end
+
+ local current = source
+ while current ~= nil do
+ if current == dest then
+ return true
+ end
+
+ current = current:parent()
+ end
+
+ return false
+end
+
return M