aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter.lua
diff options
context:
space:
mode:
authorQuentin Rasmont <qrasmont@gmail.com>2022-06-02 18:13:05 +0200
committerbfredl <bjorn.linse@gmail.com>2022-08-25 18:01:15 +0200
commit133ff6e11ea862c7425d9c6a2827b20c97cf297f (patch)
treec5b38f86c6272049ca67c7d001e4f4749d71e372 /runtime/lua/vim/treesitter.lua
parentf57341a4b69398ff0c58686e66c2f4138be164aa (diff)
downloadrneovim-133ff6e11ea862c7425d9c6a2827b20c97cf297f.tar.gz
rneovim-133ff6e11ea862c7425d9c6a2827b20c97cf297f.tar.bz2
rneovim-133ff6e11ea862c7425d9c6a2827b20c97cf297f.zip
feat(treesitter): upstream node_contains()
Util from the nvim-treesitter project.
Diffstat (limited to 'runtime/lua/vim/treesitter.lua')
-rw-r--r--runtime/lua/vim/treesitter.lua13
1 files changed, 13 insertions, 0 deletions
diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua
index 37ab59b259..0936d62296 100644
--- a/runtime/lua/vim/treesitter.lua
+++ b/runtime/lua/vim/treesitter.lua
@@ -141,4 +141,17 @@ function M.is_ancestor(dest, source)
return false
end
+---Determines if a node contains a range
+---@param node table The node
+---@param range table The range
+---
+---@returns (boolean) True if the node contains the range
+function M.node_contains(node, range)
+ local start_row, start_col, end_row, end_col = node:range()
+ local start_fits = start_row < range[1] or (start_row == range[1] and start_col <= range[2])
+ local end_fits = end_row > range[3] or (end_row == range[3] and end_col >= range[4])
+
+ return start_fits and end_fits
+end
+
return M