From fba03a304e0e8042f8330e1fe7b1ce6764a6fd16 Mon Sep 17 00:00:00 2001 From: Fabian David Schmidt Date: Fri, 12 Nov 2021 16:29:00 +0100 Subject: feat: get node at cursor of other win --- lua/nvim-treesitter/ts_utils.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/nvim-treesitter/ts_utils.lua b/lua/nvim-treesitter/ts_utils.lua index b17eccc6c..4df84e3ba 100644 --- a/lua/nvim-treesitter/ts_utils.lua +++ b/lua/nvim-treesitter/ts_utils.lua @@ -124,7 +124,13 @@ end function M.get_node_at_cursor(winnr) local cursor = api.nvim_win_get_cursor(winnr or 0) local cursor_range = { cursor[1] - 1, cursor[2] } - local root = M.get_root_for_position(unpack(cursor_range)) + + local buf = vim.api.nvim_win_get_buf(winnr) + local root_lang_tree = parsers.get_parser(buf) + if not root_lang_tree then + return + end + local root = M.get_root_for_position(cursor_range[1], cursor_range[2], root_lang_tree) if not root then return -- cgit v1.2.3-70-g09d2