mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-04 12:30:01 -04:00
add ignore_injected_langs to get_node_at_cursor
This commit is contained in:
parent
02818f8a4c
commit
9dff7c2d45
1 changed files with 9 additions and 4 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue