feat(lua): support vim.Range:has(vim.pos) #37879

This commit is contained in:
Maria Solano
2026-02-16 08:05:38 -08:00
committed by GitHub
parent 501a21f333
commit 6e1745e96e
3 changed files with 25 additions and 9 deletions

View File

@@ -106,13 +106,19 @@ function Range:is_empty()
return self.start >= self.end_
end
--- Checks whether {outer} range contains {inner} range.
--- Checks whether {outer} range contains {inner} range or position.
---
---@param outer vim.Range
---@param inner vim.Range
---@return boolean `true` if {outer} range fully contains {inner} range.
---@param inner vim.Range|vim.Pos
---@return boolean `true` if {outer} range fully contains {inner} range or position.
function Range.has(outer, inner)
return outer.start <= inner.start and outer.end_ >= inner.end_
if inner.start then
-- inner is a range
return outer.start <= inner.start and outer.end_ >= inner.end_
else
-- inner is a position
return outer.start <= inner and outer.end_ >= inner
end
end
--- Computes the common range shared by the given ranges.