aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/diagnostic.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-10-18 11:33:12 +0100
committerLewis Russell <me@lewisr.dev>2024-10-21 11:32:06 +0100
commit3572319b4cb1a4163624a5fe328886f1928dbc4a (patch)
tree5e190a6d9ca8a2e0f998ef578f895efee9450fb4 /runtime/lua/vim/diagnostic.lua
parent6fd13eeddaf5db89c1b81cc7d3d3f1a7da5401a7 (diff)
downloadrneovim-3572319b4cb1a4163624a5fe328886f1928dbc4a.tar.gz
rneovim-3572319b4cb1a4163624a5fe328886f1928dbc4a.tar.bz2
rneovim-3572319b4cb1a4163624a5fe328886f1928dbc4a.zip
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.
Diffstat (limited to 'runtime/lua/vim/diagnostic.lua')
-rw-r--r--runtime/lua/vim/diagnostic.lua56
1 files changed, 20 insertions, 36 deletions
diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua
index 3570956efd..392db5b800 100644
--- a/runtime/lua/vim/diagnostic.lua
+++ b/runtime/lua/vim/diagnostic.lua
@@ -478,7 +478,7 @@ end
--- @return vim.Diagnostic[]
local function reformat_diagnostics(format, diagnostics)
vim.validate('format', format, 'function')
- vim.validate({ diagnostics = { diagnostics, vim.islist, 'a list of diagnostics' } })
+ vim.validate('diagnostics', diagnostics, vim.islist, 'a list of diagnostics')
local formatted = vim.deepcopy(diagnostics, true)
for _, diagnostic in ipairs(formatted) do
@@ -1056,7 +1056,7 @@ end
function M.set(namespace, bufnr, diagnostics, opts)
vim.validate('namespace', namespace, 'number')
vim.validate('bufnr', bufnr, 'number')
- vim.validate({ diagnostics = { diagnostics, vim.islist, 'a list of diagnostics' } })
+ vim.validate('diagnostics', diagnostics, vim.islist, 'a list of diagnostics')
vim.validate('opts', opts, 'table', true)
bufnr = get_bufnr(bufnr)
@@ -1336,7 +1336,7 @@ M.handlers.signs = {
show = function(namespace, bufnr, diagnostics, opts)
vim.validate('namespace', namespace, 'number')
vim.validate('bufnr', bufnr, 'number')
- vim.validate({ diagnostics = { diagnostics, vim.islist, 'a list of diagnostics' } })
+ vim.validate('diagnostics', diagnostics, vim.islist, 'a list of diagnostics')
vim.validate('opts', opts, 'table', true)
bufnr = get_bufnr(bufnr)
@@ -1457,7 +1457,7 @@ M.handlers.underline = {
show = function(namespace, bufnr, diagnostics, opts)
vim.validate('namespace', namespace, 'number')
vim.validate('bufnr', bufnr, 'number')
- vim.validate({ diagnostics = { diagnostics, vim.islist, 'a list of diagnostics' } })
+ vim.validate('diagnostics', diagnostics, vim.islist, 'a list of diagnostics')
vim.validate('opts', opts, 'table', true)
bufnr = get_bufnr(bufnr)
@@ -1524,7 +1524,7 @@ M.handlers.virtual_text = {
show = function(namespace, bufnr, diagnostics, opts)
vim.validate('namespace', namespace, 'number')
vim.validate('bufnr', bufnr, 'number')
- vim.validate({ diagnostics = { diagnostics, vim.islist, 'a list of diagnostics' } })
+ vim.validate('diagnostics', diagnostics, vim.islist, 'a list of diagnostics')
vim.validate('opts', opts, 'table', true)
bufnr = get_bufnr(bufnr)
@@ -1709,15 +1709,7 @@ end
function M.show(namespace, bufnr, diagnostics, opts)
vim.validate('namespace', namespace, 'number', true)
vim.validate('bufnr', bufnr, 'number', true)
- vim.validate({
- diagnostics = {
- diagnostics,
- function(v)
- return v == nil or vim.islist(v)
- end,
- 'a list of diagnostics',
- },
- })
+ vim.validate('diagnostics', diagnostics, vim.islist, true, 'a list of diagnostics')
vim.validate('opts', opts, 'table', true)
if not bufnr or not namespace then
@@ -1869,13 +1861,7 @@ function M.open_float(opts, ...)
local highlights = {} --- @type table[]
local header = if_nil(opts.header, 'Diagnostics:')
if header then
- vim.validate({
- header = {
- header,
- { 'string', 'table' },
- "'string' or 'table'",
- },
- })
+ vim.validate('header', header, { 'string', 'table' }, "'string' or 'table'")
if type(header) == 'table' then
-- Don't insert any lines for an empty string
if string.len(if_nil(header[1], '')) > 0 then
@@ -1903,13 +1889,12 @@ function M.open_float(opts, ...)
local prefix, prefix_hl_group --- @type string?, string?
if prefix_opt then
- vim.validate({
- prefix = {
- prefix_opt,
- { 'string', 'table', 'function' },
- "'string' or 'table' or 'function'",
- },
- })
+ vim.validate(
+ 'prefix',
+ prefix_opt,
+ { 'string', 'table', 'function' },
+ "'string' or 'table' or 'function'"
+ )
if type(prefix_opt) == 'string' then
prefix, prefix_hl_group = prefix_opt, 'NormalFloat'
elseif type(prefix_opt) == 'table' then
@@ -1923,13 +1908,12 @@ function M.open_float(opts, ...)
local suffix, suffix_hl_group --- @type string?, string?
if suffix_opt then
- vim.validate({
- suffix = {
- suffix_opt,
- { 'string', 'table', 'function' },
- "'string' or 'table' or 'function'",
- },
- })
+ vim.validate(
+ 'suffix',
+ suffix_opt,
+ { 'string', 'table', 'function' },
+ "'string' or 'table' or 'function'"
+ )
if type(suffix_opt) == 'string' then
suffix, suffix_hl_group = suffix_opt, 'NormalFloat'
elseif type(suffix_opt) == 'table' then
@@ -2239,7 +2223,7 @@ local errlist_type_map = {
---@param diagnostics vim.Diagnostic[]
---@return table[] : Quickfix list items |setqflist-what|
function M.toqflist(diagnostics)
- vim.validate({ diagnostics = { diagnostics, vim.islist, 'a list of diagnostics' } })
+ vim.validate('diagnostics', diagnostics, vim.islist, 'a list of diagnostics')
local list = {} --- @type table[]
for _, v in ipairs(diagnostics) do