mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-18 11:20:07 -04:00
remove ignore_child_trees from get_node_at_position
This commit is contained in:
parent
9dff7c2d45
commit
6a437db012
1 changed files with 15 additions and 8 deletions
|
|
@ -134,7 +134,19 @@ function M.get_node_at_cursor(winnr, ignore_injected_langs)
|
||||||
if not root_lang_tree then
|
if not root_lang_tree then
|
||||||
return
|
return
|
||||||
end
|
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
|
if not root then
|
||||||
return
|
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])
|
return root:named_descendant_for_range(cursor_range[1], cursor_range[2], cursor_range[1], cursor_range[2])
|
||||||
end
|
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 root_lang_tree then
|
||||||
if not parsers.has_parser() then
|
if not parsers.has_parser() then
|
||||||
return
|
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()
|
root_lang_tree = parsers.get_parser()
|
||||||
end
|
end
|
||||||
|
|
||||||
local lang_tree
|
local lang_tree = root_lang_tree:language_for_range { line, col, line, col }
|
||||||
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
|
for _, tree in ipairs(lang_tree:trees()) do
|
||||||
local root = tree:root()
|
local root = tree:root()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue