aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua')
-rw-r--r--lua/nvim-treesitter/ts_utils.lua13
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()