feat(treesitter): upstream get_named_children() as a node method

Util from the nvim-treesitter project.
This commit is contained in:
Quentin Rasmont
2022-04-30 20:54:25 +02:00
committed by bfredl
parent 6b2d42eb03
commit a577fb778a
2 changed files with 44 additions and 0 deletions

View File

@@ -59,4 +59,22 @@ describe('treesitter node API', function()
exec_lua 'node = node:prev_named_sibling()'
eq('int x', lua_eval('node_text(node)'))
end)
it('can retrieve the children of a node', function()
insert([[
int main() {
int x = 3;
}]])
local len = exec_lua([[
tree = vim.treesitter.get_parser(0, "c"):parse()[1]
node = tree:root():child(0)
children = node:named_children()
return #children
]])
eq(3, len)
eq('<node compound_statement>', lua_eval('tostring(children[3])'))
end)
end)