mirror of
https://github.com/neovim/neovim
synced 2025-07-16 01:01:49 +00:00
feat(vim.deprecate): only issue warning if neovim version is high enough
As specified by MAINTAIN.md, features should be soft deprecated at first (meaning no warnings) to give people a chance to adjust. The problem with this approach is that deprecating a feature becomes harder than usual as during the soft deprecation period you need to remember not to issue a warning, and during the hard deprecation period you need to remember to start issuing a warning. This behavior is only enforced if the `plugin` parameter is `nil` as plugins may not want this specific behavior.
This commit is contained in:
@ -1019,6 +1019,18 @@ end
|
||||
---
|
||||
---@return string|nil # Deprecated message, or nil if no message was shown.
|
||||
function vim.deprecate(name, alternative, version, plugin, backtrace)
|
||||
-- Only issue warning if feature is hard-deprecated as specified by MAINTAIN.md.
|
||||
if plugin == nil then
|
||||
local current_version = vim.version()
|
||||
local deprecated_version = assert(vim.version.parse(version))
|
||||
local soft_deprecated_version =
|
||||
{ deprecated_version.major, deprecated_version.minor - 1, deprecated_version.patch }
|
||||
local deprecate = vim.version.lt(current_version, soft_deprecated_version)
|
||||
if deprecate then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local msg = ('%s is deprecated'):format(name)
|
||||
plugin = plugin or 'Nvim'
|
||||
msg = alternative and ('%s, use %s instead.'):format(msg, alternative) or msg
|
||||
|
Reference in New Issue
Block a user