mirror of
https://github.com/neovim/neovim.git
synced 2024-09-17 20:58:20 -04:00
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:
parent
46fab3831b
commit
ecdb6465e2
@ -226,13 +226,11 @@ function Range:has(version)
|
|||||||
if type(version) == 'string' then
|
if type(version) == 'string' then
|
||||||
---@diagnostic disable-next-line: cast-local-type
|
---@diagnostic disable-next-line: cast-local-type
|
||||||
version = M.parse(version)
|
version = M.parse(version)
|
||||||
else
|
elseif getmetatable(version) ~= Version then
|
||||||
-- Need metatable to compare versions.
|
-- Need metatable to compare versions.
|
||||||
version = setmetatable(vim.deepcopy(version), Version)
|
version = setmetatable(vim.deepcopy(version), Version)
|
||||||
end
|
end
|
||||||
if version then
|
if version then
|
||||||
-- Workaround: vim.version() reports "prerelease" as a boolean.
|
|
||||||
version.prerelease = version.prerelease or nil
|
|
||||||
if version.prerelease ~= self.from.prerelease then
|
if version.prerelease ~= self.from.prerelease then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@ -423,8 +421,12 @@ function M.parse(version, opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
setmetatable(M, {
|
setmetatable(M, {
|
||||||
|
--- Returns the current Nvim version.
|
||||||
__call = function()
|
__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,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user