mirror of
https://github.com/neovim/neovim.git
synced 2026-04-21 14:55:33 +00:00
fix(vim.version): improve construction of '<=a.b.c' and '>a.b.c' ranges
Problem: `vim.version.range('<=a.b.c')` is not precise when it comes to
its right hand side. This is due to version ranges using exclusive right
hand side. While `vim.version.range('>a.b.c')` is not precise when it
comes to its left hand side because left hand sides are inclusive.
Solution: For '>=a.b.c' increase `to` from 'a.b.c' to the smallest
reasonable version that is bigger than 'a.b.c'. For '<a.b.c' do the same
for `from`.
More proper solution is an explicit control over inclusivity of version
range sides, but it has more side effects and requires design decisions.
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
--- >1.2.3 greater than 1.2.3
|
||||
--- <1.2.3 before 1.2.3
|
||||
--- >=1.2.3 at least 1.2.3
|
||||
--- <=1.2.3 at most 1.2.3
|
||||
--- ~1.2.3 is >=1.2.3 <1.3.0 "reasonably close to 1.2.3"
|
||||
--- ^1.2.3 is >=1.2.3 <2.0.0 "compatible with 1.2.3"
|
||||
--- ^0.2.3 is >=0.2.3 <0.3.0 (0.x.x is special)
|
||||
@@ -42,7 +43,7 @@
|
||||
--- * any version
|
||||
--- x same
|
||||
---
|
||||
--- 1.2.3 - 2.3.4 is >=1.2.3 <=2.3.4
|
||||
--- 1.2.3 - 2.3.4 is >=1.2.3 <2.3.4
|
||||
---
|
||||
--- Partial right: missing pieces treated as x (2.3 => 2.3.x).
|
||||
--- 1.2.3 - 2.3 is >=1.2.3 <2.4.0
|
||||
@@ -315,9 +316,23 @@ function M.range(spec) -- Adapted from https://github.com/folke/lazy.nvim
|
||||
from = M._version({})
|
||||
elseif mods == '<=' then
|
||||
from = M._version({})
|
||||
to.patch = to.patch + 1
|
||||
-- HACK: construct the smallest reasonable version bigger than `to`
|
||||
-- to simulate `<=` while using exclusive right hand side
|
||||
if to.prerelease then
|
||||
to.prerelease = to.prerelease .. '.0'
|
||||
else
|
||||
to.patch = to.patch + 1
|
||||
to.prerelease = '0'
|
||||
end
|
||||
elseif mods == '>' then
|
||||
from.patch = from.patch + 1
|
||||
-- HACK: construct the smallest reasonable version bigger than `from`
|
||||
-- to simulate `>` while using inclusive left hand side
|
||||
if from.prerelease then
|
||||
from.prerelease = from.prerelease .. '.0'
|
||||
else
|
||||
from.patch = from.patch + 1
|
||||
from.prerelease = '0'
|
||||
end
|
||||
to = nil
|
||||
elseif mods == '>=' then
|
||||
to = nil
|
||||
|
||||
Reference in New Issue
Block a user