commit ecdb6465e272119f80f3b68a6695e0f74b02ca49
parent 46fab3831b12352b513b6ceb6d482380a71d90e4
Author: Gianmaria Bajo <mg1979.git@gmail.com>
Date: Wed, 7 Jun 2023 14:28:44 +0200
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.
Diffstat:
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/runtime/lua/vim/version.lua b/runtime/lua/vim/version.lua
@@ -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,
})