mirror of
https://github.com/neovim/neovim.git
synced 2024-12-23 12:45:17 -07:00
fix(lua): vim.deprecate does not support major>0
This commit is contained in:
parent
c9c17fda80
commit
960fdc775a
@ -79,6 +79,8 @@ When a (non-experimental) feature is slated to be removed it should:
|
|||||||
`v0.10.0-dev-1957+gd676746c33` then use `0.12`.
|
`v0.10.0-dev-1957+gd676746c33` then use `0.12`.
|
||||||
- For Vimscript features, use `v:lua.vim.deprecate()`. Use the same version
|
- For Vimscript features, use `v:lua.vim.deprecate()`. Use the same version
|
||||||
as described for Lua features.
|
as described for Lua features.
|
||||||
|
- `vim.deprecate(…, 'x.y.z')` where major version `x` is greater than the
|
||||||
|
current Nvim major version, is always treated as _soft_ deprecation.
|
||||||
2. Be _hard_ deprecated in a following a release in which it was soft deprecated.
|
2. Be _hard_ deprecated in a following a release in which it was soft deprecated.
|
||||||
- Use of the deprecated feature will still work but should issue a warning.
|
- Use of the deprecated feature will still work but should issue a warning.
|
||||||
- Features implemented in C will need bespoke implementations to communicate
|
- Features implemented in C will need bespoke implementations to communicate
|
||||||
|
@ -1149,16 +1149,22 @@ function vim.deprecate(name, alternative, version, plugin, backtrace)
|
|||||||
if plugin == 'Nvim' then
|
if plugin == 'Nvim' then
|
||||||
require('vim.deprecated.health').add(name, version, traceback(), alternative)
|
require('vim.deprecated.health').add(name, version, traceback(), alternative)
|
||||||
|
|
||||||
-- Only issue warning if feature is hard-deprecated as specified by MAINTAIN.md.
|
-- Show a warning only if feature is hard-deprecated (see MAINTAIN.md).
|
||||||
-- Example: if removal_version is 0.12 (soft-deprecated since 0.10-dev), show warnings starting at
|
-- Example: if removal `version` is 0.12 (soft-deprecated since 0.10-dev), show warnings
|
||||||
-- 0.11, including 0.11-dev
|
-- starting at 0.11, including 0.11-dev.
|
||||||
local major, minor = version:match('(%d+)%.(%d+)')
|
local major, minor = version:match('(%d+)%.(%d+)')
|
||||||
major, minor = tonumber(major), tonumber(minor)
|
major, minor = tonumber(major), tonumber(minor)
|
||||||
|
local nvim_major = 0 --- Current Nvim major version.
|
||||||
|
|
||||||
|
-- We can't "subtract" from a major version, so:
|
||||||
|
-- * Always treat `major > nvim_major` as soft-deprecation.
|
||||||
|
-- * Compare `minor - 1` if `major == nvim_major`.
|
||||||
|
if major > nvim_major then
|
||||||
|
return -- Always soft-deprecation (see MAINTAIN.md).
|
||||||
|
end
|
||||||
|
|
||||||
local hard_deprecated_since = string.format('nvim-%d.%d', major, minor - 1)
|
local hard_deprecated_since = string.format('nvim-%d.%d', major, minor - 1)
|
||||||
-- Assume there will be no next minor version before bumping up the major version
|
if major == nvim_major and vim.fn.has(hard_deprecated_since) == 0 then
|
||||||
local is_hard_deprecated = minor == 0 or vim.fn.has(hard_deprecated_since) == 1
|
|
||||||
if not is_hard_deprecated then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -155,10 +155,10 @@ describe('lua stdlib', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it('plugin=nil, no error if soft-deprecated', function()
|
it('plugin=nil, no error if soft-deprecated', function()
|
||||||
eq(
|
eq(vim.NIL, exec_lua [[return vim.deprecate('old1', 'new1', '0.99.0')]])
|
||||||
vim.NIL,
|
-- Major version > current Nvim major is always "soft-deprecated".
|
||||||
exec_lua('return vim.deprecate(...)', 'foo.baz()', 'foo.better_baz()', '0.99.0')
|
-- XXX: This is also a reminder to update the hardcoded `nvim_major`, when Nvim reaches 1.0.
|
||||||
)
|
eq(vim.NIL, exec_lua [[return vim.deprecate('old2', 'new2', '1.0.0')]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('plugin=nil, show error if hard-deprecated', function()
|
it('plugin=nil, show error if hard-deprecated', function()
|
||||||
@ -175,13 +175,6 @@ describe('lua stdlib', function()
|
|||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('plugin=nil, to be deleted in the next major version (1.0)', function()
|
|
||||||
eq(
|
|
||||||
[[foo.baz() is deprecated. Run ":checkhealth vim.deprecated" for more information]],
|
|
||||||
exec_lua [[ return vim.deprecate('foo.baz()', nil, '1.0') ]]
|
|
||||||
)
|
|
||||||
end)
|
|
||||||
|
|
||||||
it('plugin specified', function()
|
it('plugin specified', function()
|
||||||
-- When `plugin` is specified, don't show ":help deprecated". #22235
|
-- When `plugin` is specified, don't show ":help deprecated". #22235
|
||||||
eq(
|
eq(
|
||||||
|
Loading…
Reference in New Issue
Block a user