diff options
author | Lewis Russell <lewis6991@gmail.com> | 2024-10-16 17:03:48 +0100 |
---|---|---|
committer | Lewis Russell <me@lewisr.dev> | 2024-10-17 16:53:52 +0100 |
commit | 3f3e4837d5f7d2d9cb1c89bd3a5b2ee8a730772a (patch) | |
tree | 54dc9c0e06c7436d18b1863e5b26272dc1948d78 /runtime/lua/vim/shared.lua | |
parent | fa6ab0d90958516d0bc1ed62839d85405ad08fa8 (diff) | |
download | rneovim-3f3e4837d5f7d2d9cb1c89bd3a5b2ee8a730772a.tar.gz rneovim-3f3e4837d5f7d2d9cb1c89bd3a5b2ee8a730772a.tar.bz2 rneovim-3f3e4837d5f7d2d9cb1c89bd3a5b2ee8a730772a.zip |
perf(validate): use lighter version
- Also fix `vim.validate()` for PUC Lua when showing errors for values
that aren't string or number.
Diffstat (limited to 'runtime/lua/vim/shared.lua')
-rw-r--r-- | runtime/lua/vim/shared.lua | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua index 4d06cdd77d..0f636401bb 100644 --- a/runtime/lua/vim/shared.lua +++ b/runtime/lua/vim/shared.lua @@ -109,7 +109,9 @@ function vim.gsplit(s, sep, opts) if type(opts) == 'boolean' then plain = opts -- For backwards compatibility. else - vim.validate({ s = { s, 's' }, sep = { sep, 's' }, opts = { opts, 't', true } }) + vim.validate('s', s, 'string') + vim.validate('sep', sep, 'string') + vim.validate('opts', opts, 'table', true) opts = opts or {} plain, trimempty = opts.plain, opts.trimempty end @@ -303,7 +305,8 @@ end ---@param opts? vim.tbl_contains.Opts Keyword arguments |kwargs|: ---@return boolean `true` if `t` contains `value` function vim.tbl_contains(t, value, opts) - vim.validate({ t = { t, 't' }, opts = { opts, 't', true } }) + vim.validate('t', t, 'table') + vim.validate('opts', opts, 'table', true) --- @cast t table<any,any> local pred --- @type fun(v: any): boolean? @@ -550,12 +553,10 @@ end ---@param finish integer? Final index on src. Defaults to `#src` ---@return T dst function vim.list_extend(dst, src, start, finish) - vim.validate({ - dst = { dst, 't' }, - src = { src, 't' }, - start = { start, 'n', true }, - finish = { finish, 'n', true }, - }) + vim.validate('dst', dst, 'table') + vim.validate('src', src, 'table') + vim.validate('start', start, 'number', true) + vim.validate('finish', finish, 'number', true) for i = start or 1, finish or #src do table.insert(dst, src[i]) end @@ -987,6 +988,10 @@ do ok = (actual == expected) or (v == nil and optional == true) if not ok then + if not jit and (actual ~= 'string' or actual ~= 'number') then + -- PUC-Lua can only handle string and number for %s in string.format() + v = vim.inspect(v) + end err_msg = ('%s: expected %s, got %s%s'):format( name, expected, |