mirror of
https://github.com/neovim/neovim.git
synced 2025-09-10 21:38:19 +00:00
treesitter: add node:field() to get field children
This commit is contained in:
@@ -151,6 +151,34 @@ void ui_refresh(void)
|
||||
}, res)
|
||||
end)
|
||||
|
||||
it('allows to get a child by field', function()
|
||||
if not check_parser() then return end
|
||||
|
||||
insert(test_text);
|
||||
|
||||
local res = exec_lua([[
|
||||
parser = vim.treesitter.get_parser(0, "c")
|
||||
|
||||
func_node = parser:parse():root():child(0)
|
||||
|
||||
local res = {}
|
||||
for _, node in ipairs(func_node:field("type")) do
|
||||
table.insert(res, {node:type(), node:range()})
|
||||
end
|
||||
return res
|
||||
]])
|
||||
|
||||
eq({{ "primitive_type", 0, 0, 0, 4 }}, res)
|
||||
|
||||
local res_fail = exec_lua([[
|
||||
parser = vim.treesitter.get_parser(0, "c")
|
||||
|
||||
return #func_node:field("foo") == 0
|
||||
]])
|
||||
|
||||
assert(res_fail)
|
||||
end)
|
||||
|
||||
local query = [[
|
||||
((call_expression function: (identifier) @minfunc (argument_list (identifier) @min_id)) (eq? @minfunc "MIN"))
|
||||
"for" @keyword
|
||||
|
Reference in New Issue
Block a user