mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 06:28:35 +00:00
Merge pull request #15434 from Dkendal/feature-lua-treesitter-sibling
feat(treesitter): add next, prev sibling method
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user