diff options
author | Lewis Russell <lewis6991@gmail.com> | 2023-03-06 10:57:14 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-06 10:57:14 +0000 |
commit | f9a46391ab5961fe6c6b7d1efdc96befdd495c11 (patch) | |
tree | cee7f3f2bd2e34c169f9dd6c4dae0b40dd47072a /runtime/lua/vim/treesitter.lua | |
parent | b0620ffe5a2e16d6d52e803978c90d0ffb030908 (diff) | |
download | rneovim-f9a46391ab5961fe6c6b7d1efdc96befdd495c11.tar.gz rneovim-f9a46391ab5961fe6c6b7d1efdc96befdd495c11.tar.bz2 rneovim-f9a46391ab5961fe6c6b7d1efdc96befdd495c11.zip |
refactor(treesitter): simplify some range functions
Diffstat (limited to 'runtime/lua/vim/treesitter.lua')
-rw-r--r-- | runtime/lua/vim/treesitter.lua | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua index ee66ba9f9b..d13824076e 100644 --- a/runtime/lua/vim/treesitter.lua +++ b/runtime/lua/vim/treesitter.lua @@ -2,6 +2,7 @@ local a = vim.api local query = require('vim.treesitter.query') local language = require('vim.treesitter.language') local LanguageTree = require('vim.treesitter.languagetree') +local Range = require('vim.treesitter._range') ---@type table<integer,LanguageTree> local parsers = setmetatable({}, { __mode = 'v' }) @@ -190,20 +191,7 @@ end --- ---@return boolean True if the position is in node range function M.is_in_node_range(node, line, col) - local start_line, start_col, end_line, end_col = M.get_node_range(node) - if line >= start_line and line <= end_line then - if line == start_line and line == end_line then - return col >= start_col and col < end_col - elseif line == start_line then - return col >= start_col - elseif line == end_line then - return col < end_col - else - return true - end - else - return false - end + return M.node_contains(node, { line, col, line, col }) end --- Determines if a node contains a range @@ -213,11 +201,11 @@ end --- ---@return 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 + vim.validate({ + node = { node, 'userdata' }, + range = { range, Range.validate, 'integer list with 4 or 6 elements' }, + }) + return Range.contains({ node:range() }, range) end --- Returns a list of highlight captures at the given position |