perf(validate): use lighter version

- Also fix `vim.validate()` for PUC Lua when showing errors for values
  that aren't string or number.
This commit is contained in:
Lewis Russell
2024-10-16 17:03:48 +01:00
committed by Lewis Russell
parent fa6ab0d909
commit 3f3e4837d5
19 changed files with 141 additions and 253 deletions

View File

@ -473,9 +473,7 @@ do
--- @param handle? false|integer
--- @return vim.var_accessor
local function make_dict_accessor(scope, handle)
validate({
scope = { scope, 's' },
})
validate('scope', scope, 'string')
local mt = {}
function mt:__newindex(k, v)
return vim._setvar(scope, handle or 0, k, v)
@ -1171,12 +1169,10 @@ function vim.deprecate(name, alternative, version, plugin, backtrace)
local displayed = vim._truncated_echo_once(msg)
return displayed and msg or nil
else
vim.validate {
name = { name, 'string' },
alternative = { alternative, 'string', true },
version = { version, 'string', true },
plugin = { plugin, 'string', true },
}
vim.validate('name', name, 'string')
vim.validate('alternative', alternative, 'string', true)
vim.validate('version', version, 'string', true)
vim.validate('plugin', plugin, 'string', true)
local msg = ('%s is deprecated'):format(name)
msg = alternative and ('%s, use %s instead.'):format(msg, alternative) or (msg .. '.')