mirror of
https://github.com/neovim/neovim.git
synced 2026-04-21 23:05:41 +00:00
feat(treesitter): add node_for_range function
This is identical to `named_node_for_range` except that it includes anonymous nodes. This maintains consistency in the API because we already have `descendant_for_range` and `named_descendant_for_range`.
This commit is contained in:
committed by
Christian Clason
parent
01a56a056c
commit
bd3b6ec836
@@ -1133,6 +1133,18 @@ function LanguageTree:tree_for_range(range, opts)
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Gets the smallest node that contains {range}.
|
||||
---
|
||||
---@param range Range4 `{ start_line, start_col, end_line, end_col }`
|
||||
---@param opts? vim.treesitter.LanguageTree.tree_for_range.Opts
|
||||
---@return TSNode?
|
||||
function LanguageTree:node_for_range(range, opts)
|
||||
local tree = self:tree_for_range(range, opts)
|
||||
if tree then
|
||||
return tree:root():descendant_for_range(unpack(range))
|
||||
end
|
||||
end
|
||||
|
||||
--- Gets the smallest named node that contains {range}.
|
||||
---
|
||||
---@param range Range4 `{ start_line, start_col, end_line, end_col }`
|
||||
|
||||
Reference in New Issue
Block a user