mirror of
https://github.com/neovim/neovim.git
synced 2025-10-21 17:21:49 +00:00
fix(lua): vim.validate message
param #33675
Problem:
vim.validate does not handle `message` param.
Solution:
Add the missing logic.
(cherry picked from commit 40351bbbbe
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
c753e70abb
commit
dc87a0d80a
@@ -854,7 +854,7 @@ do
|
||||
--- @param param_name string
|
||||
--- @param val any
|
||||
--- @param validator vim.validate.Validator
|
||||
--- @param message? string
|
||||
--- @param message? string "Expected" message
|
||||
--- @param allow_alias? boolean Allow short type names: 'n', 's', 't', 'b', 'f', 'c'
|
||||
--- @return string?
|
||||
local function is_valid(param_name, val, validator, message, allow_alias)
|
||||
@@ -866,18 +866,18 @@ do
|
||||
end
|
||||
|
||||
if not is_type(val, expected) then
|
||||
return string.format('%s: expected %s, got %s', param_name, expected, type(val))
|
||||
return ('%s: expected %s, got %s'):format(param_name, message or expected, type(val))
|
||||
end
|
||||
elseif vim.is_callable(validator) then
|
||||
-- Check user-provided validation function
|
||||
local valid, opt_msg = validator(val)
|
||||
if not valid then
|
||||
local err_msg =
|
||||
string.format('%s: expected %s, got %s', param_name, message or '?', tostring(val))
|
||||
|
||||
if opt_msg then
|
||||
err_msg = string.format('%s. Info: %s', err_msg, opt_msg)
|
||||
end
|
||||
local err_msg = ('%s: expected %s, got %s'):format(
|
||||
param_name,
|
||||
message or '?',
|
||||
tostring(val)
|
||||
)
|
||||
err_msg = opt_msg and ('%s. Info: %s'):format(err_msg, opt_msg) or err_msg
|
||||
|
||||
return err_msg
|
||||
end
|
||||
|
Reference in New Issue
Block a user