diff options
author | Thomas Vigouroux <tomvig38@gmail.com> | 2021-08-23 09:14:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-23 09:14:40 +0200 |
commit | 34b60ec894dd0c7347c13916c71c48404dd76421 (patch) | |
tree | 773e9dc883b012f1abc8b692f182afc5ffc83500 /src | |
parent | 4b3ffde20856bd9da8386317490bb1a9fbf34b3a (diff) | |
parent | 140084180e82bea3afafa32a33fee37e6e9473ca (diff) | |
download | rneovim-34b60ec894dd0c7347c13916c71c48404dd76421.tar.gz rneovim-34b60ec894dd0c7347c13916c71c48404dd76421.tar.bz2 rneovim-34b60ec894dd0c7347c13916c71c48404dd76421.zip |
Merge pull request #15434 from Dkendal/feature-lua-treesitter-sibling
feat(treesitter): add next, prev sibling method
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 2d83620dcd..ed475c324f 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 } }; @@ -990,6 +994,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) { |