diff options
| author | Marcus Caisey <marcus@teckna.com> | 2022-04-03 13:57:31 +0100 |
|---|---|---|
| committer | Stephan Seitz <stephan.seitz@fau.de> | 2022-04-16 10:42:18 +0200 |
| commit | 9dff7c2d45f25d6b66ee0c7d8509385829a0a476 (patch) | |
| tree | b7166ba3fb840f44fcfb0f4bc62ec0903c434eff /lua | |
| parent | ci: remove all swift skips (diff) | |
| download | nvim-treesitter-9dff7c2d45f25d6b66ee0c7d8509385829a0a476.tar nvim-treesitter-9dff7c2d45f25d6b66ee0c7d8509385829a0a476.tar.gz nvim-treesitter-9dff7c2d45f25d6b66ee0c7d8509385829a0a476.tar.bz2 nvim-treesitter-9dff7c2d45f25d6b66ee0c7d8509385829a0a476.tar.lz nvim-treesitter-9dff7c2d45f25d6b66ee0c7d8509385829a0a476.tar.xz nvim-treesitter-9dff7c2d45f25d6b66ee0c7d8509385829a0a476.tar.zst nvim-treesitter-9dff7c2d45f25d6b66ee0c7d8509385829a0a476.zip | |
add ignore_injected_langs to get_node_at_cursor
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim-treesitter/ts_utils.lua | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lua/nvim-treesitter/ts_utils.lua b/lua/nvim-treesitter/ts_utils.lua index 5b7023c57..74de7001c 100644 --- a/lua/nvim-treesitter/ts_utils.lua +++ b/lua/nvim-treesitter/ts_utils.lua @@ -124,7 +124,7 @@ function M.get_named_children(node) return nodes end -function M.get_node_at_cursor(winnr) +function M.get_node_at_cursor(winnr, ignore_injected_langs) winnr = winnr or 0 local cursor = api.nvim_win_get_cursor(winnr) local cursor_range = { cursor[1] - 1, cursor[2] } @@ -134,7 +134,7 @@ function M.get_node_at_cursor(winnr) if not root_lang_tree then return end - local root = M.get_root_for_position(cursor_range[1], cursor_range[2], root_lang_tree) + local root = M.get_root_for_position(cursor_range[1], cursor_range[2], root_lang_tree, ignore_injected_langs) if not root then return @@ -143,7 +143,7 @@ function M.get_node_at_cursor(winnr) 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) +function M.get_root_for_position(line, col, root_lang_tree, exclude_child_trees) if not root_lang_tree then if not parsers.has_parser() then return @@ -152,7 +152,12 @@ function M.get_root_for_position(line, col, root_lang_tree) root_lang_tree = parsers.get_parser() end - local lang_tree = root_lang_tree:language_for_range { line, col, line, col } + 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 for _, tree in ipairs(lang_tree:trees()) do local root = tree:root() |
