diff options
| author | Marcus Caisey <marcus@teckna.com> | 2022-04-03 15:35:13 +0100 |
|---|---|---|
| committer | Stephan Seitz <stephan.seitz@fau.de> | 2022-04-16 10:42:18 +0200 |
| commit | 6a437db0124823f9fe89c1de9a3b536ce1f103f3 (patch) | |
| tree | 06a4a70c0a4d91e98ee7d48331faf0bf938eda05 /lua | |
| parent | add ignore_injected_langs to get_node_at_cursor (diff) | |
| download | nvim-treesitter-6a437db0124823f9fe89c1de9a3b536ce1f103f3.tar nvim-treesitter-6a437db0124823f9fe89c1de9a3b536ce1f103f3.tar.gz nvim-treesitter-6a437db0124823f9fe89c1de9a3b536ce1f103f3.tar.bz2 nvim-treesitter-6a437db0124823f9fe89c1de9a3b536ce1f103f3.tar.lz nvim-treesitter-6a437db0124823f9fe89c1de9a3b536ce1f103f3.tar.xz nvim-treesitter-6a437db0124823f9fe89c1de9a3b536ce1f103f3.tar.zst nvim-treesitter-6a437db0124823f9fe89c1de9a3b536ce1f103f3.zip | |
remove ignore_child_trees from get_node_at_position
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-treesitter/ts_utils.lua | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/lua/nvim-treesitter/ts_utils.lua b/lua/nvim-treesitter/ts_utils.lua index 74de7001c..07bf8ab33 100644 --- a/lua/nvim-treesitter/ts_utils.lua +++ b/lua/nvim-treesitter/ts_utils.lua @@ -134,7 +134,19 @@ function M.get_node_at_cursor(winnr, ignore_injected_langs) if not root_lang_tree then return end - local root = M.get_root_for_position(cursor_range[1], cursor_range[2], root_lang_tree, ignore_injected_langs) + + local root + if ignore_injected_langs then + for _, tree in ipairs(root_lang_tree:trees()) do + local tree_root = tree:root() + if tree_root and M.is_in_node_range(tree_root, cursor_range[1], cursor_range[2]) then + root = tree_root + break + end + end + else + root = M.get_root_for_position(cursor_range[1], cursor_range[2], root_lang_tree) + end if not root then return @@ -143,7 +155,7 @@ function M.get_node_at_cursor(winnr, ignore_injected_langs) return root:named_descendant_for_range(cursor_range[1], cursor_range[2], cursor_range[1], cursor_range[2]) end -function M.get_root_for_position(line, col, root_lang_tree, exclude_child_trees) +function M.get_root_for_position(line, col, root_lang_tree) if not root_lang_tree then if not parsers.has_parser() then return @@ -152,12 +164,7 @@ function M.get_root_for_position(line, col, root_lang_tree, exclude_child_trees) root_lang_tree = parsers.get_parser() end - local lang_tree - if exclude_child_trees then - lang_tree = root_lang_tree - else - lang_tree = root_lang_tree:language_for_range { line, col, line, col } - end + local lang_tree = root_lang_tree:language_for_range { line, col, line, col } for _, tree in ipairs(lang_tree:trees()) do local root = tree:root() |
