mirror of
https://github.com/neovim/neovim
synced 2025-07-16 01:01:49 +00:00
fix(lua): vim.validate message
param #33675
Problem: vim.validate does not handle `message` param. Solution: Add the missing logic.
This commit is contained in:
@ -865,7 +865,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)
|
||||
@ -877,18 +877,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