mirror of
https://github.com/neovim/neovim
synced 2025-07-16 01:01:49 +00:00
feat(vim.validate): improve fast form and deprecate spec form
Problem: `vim.validate()` takes two forms when it only needs one. Solution: - Teach the fast form all the features of the spec form. - Deprecate the spec form. - General optimizations for both forms. - Add a `message` argument which can be used alongside or in place of the `optional` argument.
This commit is contained in:
committed by
Lewis Russell
parent
6fd13eedda
commit
3572319b4c
@ -467,13 +467,11 @@ vim.cmd = setmetatable({}, {
|
||||
|
||||
-- These are the vim.env/v/g/o/bo/wo variable magic accessors.
|
||||
do
|
||||
local validate = vim.validate
|
||||
|
||||
--- @param scope string
|
||||
--- @param handle? false|integer
|
||||
--- @return vim.var_accessor
|
||||
local function make_dict_accessor(scope, handle)
|
||||
validate('scope', scope, 'string')
|
||||
vim.validate('scope', scope, 'string')
|
||||
local mt = {}
|
||||
function mt:__newindex(k, v)
|
||||
return vim._setvar(scope, handle or 0, k, v)
|
||||
@ -589,7 +587,7 @@ end
|
||||
---@param timeout integer Number of milliseconds to wait before calling `fn`
|
||||
---@return table timer luv timer object
|
||||
function vim.defer_fn(fn, timeout)
|
||||
vim.validate({ fn = { fn, 'c', true } })
|
||||
vim.validate('fn', fn, 'callable', true)
|
||||
local timer = assert(vim.uv.new_timer())
|
||||
timer:start(
|
||||
timeout,
|
||||
@ -680,10 +678,8 @@ function vim.on_key(fn, ns_id)
|
||||
return vim.tbl_count(on_key_cbs)
|
||||
end
|
||||
|
||||
vim.validate({
|
||||
fn = { fn, 'c', true },
|
||||
ns_id = { ns_id, 'n', true },
|
||||
})
|
||||
vim.validate('fn', fn, 'callable', true)
|
||||
vim.validate('ns_id', ns_id, 'number', true)
|
||||
|
||||
if ns_id == nil or ns_id == 0 then
|
||||
ns_id = vim.api.nvim_create_namespace('')
|
||||
|
Reference in New Issue
Block a user