aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/_editor.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-10-18 11:33:12 +0100
committerLewis Russell <me@lewisr.dev>2024-10-21 11:32:06 +0100
commit3572319b4cb1a4163624a5fe328886f1928dbc4a (patch)
tree5e190a6d9ca8a2e0f998ef578f895efee9450fb4 /runtime/lua/vim/_editor.lua
parent6fd13eeddaf5db89c1b81cc7d3d3f1a7da5401a7 (diff)
downloadrneovim-3572319b4cb1a4163624a5fe328886f1928dbc4a.tar.gz
rneovim-3572319b4cb1a4163624a5fe328886f1928dbc4a.tar.bz2
rneovim-3572319b4cb1a4163624a5fe328886f1928dbc4a.zip
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.
Diffstat (limited to 'runtime/lua/vim/_editor.lua')
-rw-r--r--runtime/lua/vim/_editor.lua12
1 files changed, 4 insertions, 8 deletions
diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua
index 7aba7498f9..58283ac64b 100644
--- a/runtime/lua/vim/_editor.lua
+++ b/runtime/lua/vim/_editor.lua
@@ -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('')