aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/version.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2026-09-25 17:07:21 +0100
committerLewis Russell <lewis6991@gmail.com>2026-09-25 17:07:21 +0100
commitffa782066c2e02a068171963aded4bb300c25663 (patch)
tree9d8bfec14e7f28909af9981b5228c7b51f841b3d /runtime/lua/vim/version.lua
parent7e8ad7c52ac28c01563128d8f43996512676324c (diff)
downloadrneovim-ffa782066c2e02a068171963aded4bb300c25663.tar.gz
rneovim-ffa782066c2e02a068171963aded4bb300c25663.tar.bz2
rneovim-ffa782066c2e02a068171963aded4bb300c25663.zip
fix(lua): enable assignment type checking in runtime code
Enable EmmyLua's assign-type-mismatch diagnostic after correcting the runtime annotations and assignments it flags. Correct option, tuple, and return types, and use separate locals when a value changes representation. Add guards and narrow casts where needed so the runtime passes the stricter check. Regenerate the affected docs. AI-assisted
Diffstat (limited to 'runtime/lua/vim/version.lua')
-rw-r--r--runtime/lua/vim/version.lua24
1 files changed, 11 insertions, 13 deletions
diff --git a/runtime/lua/vim/version.lua b/runtime/lua/vim/version.lua
index a1c8137474..cf3662e177 100644
--- a/runtime/lua/vim/version.lua
+++ b/runtime/lua/vim/version.lua
@@ -68,7 +68,6 @@ local M = {}
---@field prerelease? string
---@field build? string
local Version = {}
-Version.__index = Version
--- Compares prerelease strings: per semver, number parts must be must be treated as numbers:
--- "pre1.10" is greater than "pre1.2". https://semver.org/#spec-item-11
@@ -180,12 +179,11 @@ function M._version(version, strict) -- Adapted from https://github.com/folke/la
end
if not strict then -- TODO: add more "scrubbing".
- --- @cast version string
- version = version:match('%d[^ ]*')
- end
-
- if version == nil then
- return nil
+ local scrubbed = version:match('%d[^ ]*')
+ if not scrubbed then
+ return nil
+ end
+ version = scrubbed
end
local prerel = version:match('%-([^+]*)')
@@ -261,15 +259,15 @@ local VersionRange = {}
--- @return boolean
function VersionRange:has(version)
if type(version) == 'string' then
- ---@diagnostic disable-next-line: cast-local-type
- version = M.parse(version)
+ local parsed = M.parse(version)
+ if not parsed then
+ return false
+ end
+ version = parsed
elseif getmetatable(version) ~= Version then
-- Need metatable to compare versions.
version = setmetatable(vim.deepcopy(version, true), Version)
end
- if not version then
- return false
- end
if self.from == self.to then
return version == self.from
end
@@ -310,8 +308,8 @@ function M.range(spec) -- Adapted from https://github.com/folke/lazy.nvim
to = rb and (#parts == 3 and rb.from or rb.to),
}, range_mt)
end
- ---@type string, string
local mods, version = spec:lower():match('^([%^=<>~]*)(.*)$')
+ assert(mods and version) -- The pattern matches every string.
version = version:gsub('%.[%*x]', '')
local parts = vim.split(version:gsub('%-.*', ''), '.', { plain = true })
if #parts < 3 and mods == '' then