From 3f3e4837d5f7d2d9cb1c89bd3a5b2ee8a730772a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 16 Oct 2024 17:03:48 +0100 Subject: perf(validate): use lighter version - Also fix `vim.validate()` for PUC Lua when showing errors for values that aren't string or number. --- runtime/lua/vim/_watch.lua | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'runtime/lua/vim/_watch.lua') diff --git a/runtime/lua/vim/_watch.lua b/runtime/lua/vim/_watch.lua index 11f6742941..7a306d1123 100644 --- a/runtime/lua/vim/_watch.lua +++ b/runtime/lua/vim/_watch.lua @@ -59,11 +59,9 @@ end --- @param callback vim._watch.Callback Callback for new events --- @return fun() cancel Stops the watcher function M.watch(path, opts, callback) - vim.validate({ - path = { path, 'string', false }, - opts = { opts, 'table', true }, - callback = { callback, 'function', false }, - }) + vim.validate('path', path, 'string', false) + vim.validate('opts', opts, 'table', true) + vim.validate('callback', callback, 'function', false) opts = opts or {} @@ -127,11 +125,9 @@ end --- @param callback vim._watch.Callback Callback for new events --- @return fun() cancel Stops the watcher function M.watchdirs(path, opts, callback) - vim.validate({ - path = { path, 'string', false }, - opts = { opts, 'table', true }, - callback = { callback, 'function', false }, - }) + vim.validate('path', path, 'string', false) + vim.validate('opts', opts, 'table', true) + vim.validate('callback', callback, 'function', false) opts = opts or {} local debounce = opts.debounce or 500 -- cgit From 3572319b4cb1a4163624a5fe328886f1928dbc4a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 18 Oct 2024 11:33:12 +0100 Subject: 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. --- runtime/lua/vim/_watch.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'runtime/lua/vim/_watch.lua') diff --git a/runtime/lua/vim/_watch.lua b/runtime/lua/vim/_watch.lua index 7a306d1123..13894c6147 100644 --- a/runtime/lua/vim/_watch.lua +++ b/runtime/lua/vim/_watch.lua @@ -59,9 +59,9 @@ end --- @param callback vim._watch.Callback Callback for new events --- @return fun() cancel Stops the watcher function M.watch(path, opts, callback) - vim.validate('path', path, 'string', false) + vim.validate('path', path, 'string') vim.validate('opts', opts, 'table', true) - vim.validate('callback', callback, 'function', false) + vim.validate('callback', callback, 'function') opts = opts or {} @@ -125,9 +125,9 @@ end --- @param callback vim._watch.Callback Callback for new events --- @return fun() cancel Stops the watcher function M.watchdirs(path, opts, callback) - vim.validate('path', path, 'string', false) + vim.validate('path', path, 'string') vim.validate('opts', opts, 'table', true) - vim.validate('callback', callback, 'function', false) + vim.validate('callback', callback, 'function') opts = opts or {} local debounce = opts.debounce or 500 -- cgit