feat: vim.version() returns a Version object

- vim.version() returns a Version object.
  Makes it printable and removes the need of workarounds when passing it
  to other vim.version methods.
This commit is contained in:
Gianmaria Bajo 2023-06-07 14:28:44 +02:00 committed by Justin M. Keyes
parent 46fab3831b
commit ecdb6465e2

View File

@ -226,13 +226,11 @@ function Range:has(version)
if type(version) == 'string' then
---@diagnostic disable-next-line: cast-local-type
version = M.parse(version)
else
elseif getmetatable(version) ~= Version then
-- Need metatable to compare versions.
version = setmetatable(vim.deepcopy(version), Version)
end
if version then
-- Workaround: vim.version() reports "prerelease" as a boolean.
version.prerelease = version.prerelease or nil
if version.prerelease ~= self.from.prerelease then
return false
end
@ -423,8 +421,12 @@ function M.parse(version, opts)
end
setmetatable(M, {
--- Returns the current Nvim version.
__call = function()
return vim.fn.api_info().version
local version = vim.fn.api_info().version
-- Workaround: vim.fn.api_info().version reports "prerelease" as a boolean.
version.prerelease = version.prerelease or nil
return setmetatable(version, Version)
end,
})