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 /src | |
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 'src')
-rw-r--r-- | src/nvim/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/nvim/lua/treesitter.c | 14 |
2 files changed, 13 insertions, 3 deletions
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index 8819da1ae5..0ba2eeb376 100644 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -31,7 +31,7 @@ target_link_libraries(main_lib INTERFACE ${LUV_LIBRARY}) find_package(Iconv REQUIRED) find_package(Libuv 1.28.0 REQUIRED) find_package(Lpeg REQUIRED) -find_package(Treesitter 0.23.0 REQUIRED) +find_package(Treesitter 0.24.0 REQUIRED) find_package(Unibilium 2.0 REQUIRED) find_package(UTF8proc REQUIRED) diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index ab97704dfe..819ec41390 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -828,6 +828,7 @@ static struct luaL_Reg node_meta[] = { { "parent", node_parent }, { "__has_ancestor", __has_ancestor }, { "child_containing_descendant", node_child_containing_descendant }, + { "child_with_descendant", node_child_with_descendant }, { "iter_children", node_iter_children }, { "next_sibling", node_next_sibling }, { "prev_sibling", node_prev_sibling }, @@ -1146,7 +1147,7 @@ static int __has_ancestor(lua_State *L) int const pred_len = (int)lua_objlen(L, 2); TSNode node = ts_tree_root_node(descendant.tree); - while (!ts_node_is_null(node)) { + while (node.id != descendant.id) { char const *node_type = ts_node_type(node); size_t node_type_len = strlen(node_type); @@ -1163,7 +1164,7 @@ static int __has_ancestor(lua_State *L) lua_pop(L, 1); } - node = ts_node_child_containing_descendant(node, descendant); + node = ts_node_child_with_descendant(node, descendant); } lua_pushboolean(L, false); @@ -1179,6 +1180,15 @@ static int node_child_containing_descendant(lua_State *L) return 1; } +static int node_child_with_descendant(lua_State *L) +{ + TSNode node = node_check(L, 1); + TSNode descendant = node_check(L, 2); + TSNode child = ts_node_child_with_descendant(node, descendant); + push_node(L, child, 1); + return 1; +} + static int node_next_sibling(lua_State *L) { TSNode node = node_check(L, 1); |