fix(treesitter): allow passing lang to vim.treesitter.get_node() now correctly takes opts.lang (#26360)

PROBLEM: `vim.treesitter.get_node()` does not recognize the `lang` in
the option table. This option was used in somewhere else, for instance,
`vim.treesitter.dev` (for `inspect_tree`) but was never implemented.

SOLUTION: Make `get_node()` correctly use `opts.lang` when getting a
treesitter parser.
This commit is contained in:
Jongwook Choi
2023-12-04 04:00:49 -05:00
committed by GitHub
parent 589f4761ee
commit cf612c64b0
3 changed files with 18 additions and 1 deletions

View File

@@ -40,6 +40,20 @@ describe('treesitter node API', function()
assert_alive()
end)
it('get_node() with lang given', function()
-- this buffer doesn't have filetype set!
insert('local foo = function() end')
exec_lua([[
node = vim.treesitter.get_node({
bufnr = 0,
pos = { 0, 6 }, -- on "foo"
lang = 'lua',
})
]])
eq('foo', lua_eval('vim.treesitter.query.get_node_text(node, 0)'))
eq('identifier', lua_eval('node:type()'))
end)
it('can move between siblings', function()
insert([[
int main(int x, int y, int z) {