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:
Justin M. Keyes
2025-05-04 16:36:32 -07:00
committed by GitHub
parent 0862c1036a
commit 40351bbbbe
4 changed files with 28 additions and 15 deletions

View File

@ -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