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.
This commit is contained in:
Lewis Russell
2024-10-18 11:33:12 +01:00
committed by Lewis Russell
parent 6fd13eedda
commit 3572319b4c
20 changed files with 355 additions and 374 deletions

View File

@ -325,10 +325,8 @@ function M.commit(dependency_name, commit)
end
function M.version(dependency_name, version)
vim.validate {
dependency_name = { dependency_name, 's' },
version = { version, 's' },
}
vim.validate('dependency_name', dependency_name, 'string')
vim.validate('version', version, 'string')
local dependency = assert(get_dependency(dependency_name))
verify_cmakelists_committed()
local commit_sha = get_gh_commit_sha(dependency.repo, version)

View File

@ -1289,25 +1289,15 @@ end
---
--- @return nvim.gen_help_html.gen_result result
function M.gen(help_dir, to_dir, include, commit, parser_path)
vim.validate {
help_dir = {
help_dir,
function(d)
return vim.fn.isdirectory(vim.fs.normalize(d)) == 1
end,
'valid directory',
},
to_dir = { to_dir, 's' },
include = { include, 't', true },
commit = { commit, 's', true },
parser_path = {
parser_path,
function(f)
return f == nil or vim.fn.filereadable(vim.fs.normalize(f)) == 1
end,
'valid vimdoc.{so,dll} filepath',
},
}
vim.validate('help_dir', help_dir, function(d)
return vim.fn.isdirectory(vim.fs.normalize(d)) == 1
end, 'valid directory')
vim.validate('to_dir', to_dir, 'string')
vim.validate('include', include, 'table', true)
vim.validate('commit', commit, 'sring', true)
vim.validate('parser_path', parser_path, function(f)
return vim.fn.filereadable(vim.fs.normalize(f)) == 1
end, true, 'valid vimdoc.{so,dll} filepath')
local err_count = 0
local redirects_count = 0
@ -1410,23 +1400,13 @@ end
---
--- @return nvim.gen_help_html.validate_result result
function M.validate(help_dir, include, parser_path)
vim.validate {
help_dir = {
help_dir,
function(d)
return vim.fn.isdirectory(vim.fs.normalize(d)) == 1
end,
'valid directory',
},
include = { include, 't', true },
parser_path = {
parser_path,
function(f)
return f == nil or vim.fn.filereadable(vim.fs.normalize(f)) == 1
end,
'valid vimdoc.{so,dll} filepath',
},
}
vim.validate('help_dir', help_dir, function(d)
return vim.fn.isdirectory(vim.fs.normalize(d)) == 1
end, 'valid directory')
vim.validate('include', include, 'table', true)
vim.validate('parser_path', parser_path, function(f)
return vim.fn.filereadable(vim.fs.normalize(f)) == 1
end, true, 'valid vimdoc.{so,dll} filepath')
local err_count = 0 ---@type integer
local files_to_errors = {} ---@type table<string, string[]>
ensure_runtimepath()