diff options
author | Dylan Kendal <dylankendal@gmail.com> | 2021-08-20 01:35:25 -0400 |
---|---|---|
committer | Dylan Kendal <dylankendal@gmail.com> | 2021-08-20 11:58:15 -0400 |
commit | 140084180e82bea3afafa32a33fee37e6e9473ca (patch) | |
tree | 73c33ba7ddb3fd954fa78f6003c55997b836266f /src | |
parent | 2ae9ff128583984145ce38e61bbe9047871616bf (diff) | |
download | rneovim-140084180e82bea3afafa32a33fee37e6e9473ca.tar.gz rneovim-140084180e82bea3afafa32a33fee37e6e9473ca.tar.bz2 rneovim-140084180e82bea3afafa32a33fee37e6e9473ca.zip |
feat(treesitter): add next, prev sibling method
Add tsnode methods to change to the next, previous, named or unnamed
nodes.
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/lua/treesitter.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index 1425baacf0..2dfcd9a958 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -80,6 +80,10 @@ static struct luaL_Reg node_meta[] = { { "parent", node_parent }, { "iter_children", node_iter_children }, { "_rawquery", node_rawquery }, + { "next_sibling", node_next_sibling }, + { "prev_sibling", node_prev_sibling }, + { "next_named_sibling", node_next_named_sibling }, + { "prev_named_sibling", node_prev_named_sibling }, { NULL, NULL } }; @@ -992,6 +996,50 @@ static int node_parent(lua_State *L) return 1; } +static int node_next_sibling(lua_State *L) +{ + TSNode node; + if (!node_check(L, 1, &node)) { + return 0; + } + TSNode sibling = ts_node_next_sibling(node); + push_node(L, sibling, 1); + return 1; +} + +static int node_prev_sibling(lua_State *L) +{ + TSNode node; + if (!node_check(L, 1, &node)) { + return 0; + } + TSNode sibling = ts_node_prev_sibling(node); + push_node(L, sibling, 1); + return 1; +} + +static int node_next_named_sibling(lua_State *L) +{ + TSNode node; + if (!node_check(L, 1, &node)) { + return 0; + } + TSNode sibling = ts_node_next_named_sibling(node); + push_node(L, sibling, 1); + return 1; +} + +static int node_prev_named_sibling(lua_State *L) +{ + TSNode node; + if (!node_check(L, 1, &node)) { + return 0; + } + TSNode sibling = ts_node_prev_named_sibling(node); + push_node(L, sibling, 1); + return 1; +} + /// assumes the match table being on top of the stack static void set_match(lua_State *L, TSQueryMatch *match, int nodeidx) { |