From cf612c64b0fc87c399bc5c72735335c5e73d6de1 Mon Sep 17 00:00:00 2001 From: Jongwook Choi Date: Mon, 4 Dec 2023 04:00:49 -0500 Subject: 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. --- test/functional/treesitter/node_spec.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/functional/treesitter/node_spec.lua') diff --git a/test/functional/treesitter/node_spec.lua b/test/functional/treesitter/node_spec.lua index eef75d0e91..16ead69649 100644 --- a/test/functional/treesitter/node_spec.lua +++ b/test/functional/treesitter/node_spec.lua @@ -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) { -- cgit From 04f2f864e270e772c6326cefdf24947f0130e492 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 3 Jan 2024 02:09:18 +0100 Subject: refactor: format test/* --- test/functional/treesitter/node_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/treesitter/node_spec.lua') diff --git a/test/functional/treesitter/node_spec.lua b/test/functional/treesitter/node_spec.lua index 16ead69649..c852e25ea6 100644 --- a/test/functional/treesitter/node_spec.lua +++ b/test/functional/treesitter/node_spec.lua @@ -9,7 +9,7 @@ local assert_alive = helpers.assert_alive before_each(clear) local function lua_eval(lua_expr) - return exec_lua("return " .. lua_expr) + return exec_lua('return ' .. lua_expr) end describe('treesitter node API', function() -- cgit From 649dd00fe2e54183cc210f24d36504a61e5ea605 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 8 Mar 2024 11:23:17 +0100 Subject: feat!: remove deprecated functions --- test/functional/treesitter/node_spec.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'test/functional/treesitter/node_spec.lua') diff --git a/test/functional/treesitter/node_spec.lua b/test/functional/treesitter/node_spec.lua index c852e25ea6..f114d36823 100644 --- a/test/functional/treesitter/node_spec.lua +++ b/test/functional/treesitter/node_spec.lua @@ -50,7 +50,7 @@ describe('treesitter node API', function() lang = 'lua', }) ]]) - eq('foo', lua_eval('vim.treesitter.query.get_node_text(node, 0)')) + eq('foo', lua_eval('vim.treesitter.get_node_text(node, 0)')) eq('identifier', lua_eval('node:type()')) end) @@ -62,14 +62,13 @@ describe('treesitter node API', function() ]]) exec_lua([[ - query = require"vim.treesitter.query" parser = vim.treesitter.get_parser(0, "c") tree = parser:parse()[1] root = tree:root() lang = vim.treesitter.language.inspect('c') function node_text(node) - return query.get_node_text(node, 0) + return vim.treesitter.get_node_text(node, 0) end ]]) -- cgit