diff options
author | Riley Bruins <ribru17@hotmail.com> | 2024-10-02 10:34:14 -0700 |
---|---|---|
committer | Christian Clason <c.clason@uni-graz.at> | 2024-10-11 17:29:45 +0200 |
commit | 267c7525f738cdd6024c39da758e885c026ffaaa (patch) | |
tree | 869fcb5fa87b4f9b2c4f0a0295498c5ed2883b73 /runtime/lua/vim | |
parent | c4762b309714897615607f135aab9d7bcc763c4f (diff) | |
download | rneovim-267c7525f738cdd6024c39da758e885c026ffaaa.tar.gz rneovim-267c7525f738cdd6024c39da758e885c026ffaaa.tar.bz2 rneovim-267c7525f738cdd6024c39da758e885c026ffaaa.zip |
feat(treesitter): introduce child_with_descendant()
This commit also marks `child_containing_descendant()` as deprecated
(per upstream's documentation), and uses `child_with_descendant()` in
its place. Minimum required tree-sitter version will now be `0.24`.
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r-- | runtime/lua/vim/treesitter.lua | 3 | ||||
-rw-r--r-- | runtime/lua/vim/treesitter/_meta/tsnode.lua | 18 |
2 files changed, 18 insertions, 3 deletions
diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua index ed7d31e1f7..4727c0d61d 100644 --- a/runtime/lua/vim/treesitter.lua +++ b/runtime/lua/vim/treesitter.lua @@ -152,8 +152,7 @@ function M.is_ancestor(dest, source) return false end - -- child_containing_descendant returns nil if dest is a direct parent - return source:parent() == dest or dest:child_containing_descendant(source) ~= nil + return dest:child_with_descendant(source) ~= nil end --- Returns the node's range or an unpacked range table diff --git a/runtime/lua/vim/treesitter/_meta/tsnode.lua b/runtime/lua/vim/treesitter/_meta/tsnode.lua index acc9f8d24e..d982b6a505 100644 --- a/runtime/lua/vim/treesitter/_meta/tsnode.lua +++ b/runtime/lua/vim/treesitter/_meta/tsnode.lua @@ -15,7 +15,7 @@ error('Cannot require a meta file') local TSNode = {} -- luacheck: no unused --- Get the node's immediate parent. ---- Prefer |TSNode:child_containing_descendant()| +--- Prefer |TSNode:child_with_descendant()| --- for iterating over the node's ancestors. --- @return TSNode? function TSNode:parent() end @@ -71,8 +71,24 @@ function TSNode:named_child(index) end --- Get the node's child that contains {descendant}. --- @param descendant TSNode --- @return TSNode? +--- @deprecated function TSNode:child_containing_descendant(descendant) end +--- Get the node's child that contains {descendant} (includes {descendant}). +--- +--- For example, with the following node hierarchy: +--- +--- ``` +--- a -> b -> c +--- +--- a:child_with_descendant(c) == b +--- a:child_with_descendant(b) == b +--- a:child_with_descendant(a) == nil +--- ``` +--- @param descendant TSNode +--- @return TSNode? +function TSNode:child_with_descendant(descendant) end + --- Get the node's start position. Return three values: the row, column and --- total byte count (all zero-based). --- @return integer, integer, integer |