mirror of
https://github.com/neovim/neovim.git
synced 2026-05-24 05:40:08 +00:00
feat(diagnostic)!: deprecate format as a table #39603
This commit is contained in:
@@ -177,37 +177,34 @@ local M = vim._defer_require('vim.diagnostic', {
|
||||
|
||||
--- @class vim.diagnostic.Opts.Status
|
||||
---
|
||||
--- Either:
|
||||
--- - a table mapping |diagnostic-severity| to the text to use for each
|
||||
--- existing severity section.
|
||||
--- - a function that accepts a mapping of |diagnostic-severity| to the
|
||||
--- number of diagnostics of the corresponding severity (only those
|
||||
--- severity levels that have at least 1 diagnostic) and returns
|
||||
--- a 'statusline' component. In this case highlights must be applied
|
||||
--- by the user in the `format` function. Example:
|
||||
--- ```lua
|
||||
--- local signs = {
|
||||
--- [vim.diagnostic.severity.ERROR] = "A",
|
||||
--- -- ...
|
||||
--- }
|
||||
--- local hl_map = {
|
||||
--- [vim.diagnostic.severity.ERROR] = 'DiagnosticSignError',
|
||||
--- -- ...
|
||||
--- }
|
||||
--- vim.diagnostic.config({
|
||||
--- status = {
|
||||
--- format = function(counts)
|
||||
--- local items = {}
|
||||
--- for level, _ in ipairs(vim.diagnostic.severity) do
|
||||
--- local count = counts[level] or 0
|
||||
--- table.insert(items, ("%%#%s#%s %s"):format(hl_map[level], signs[level], count))
|
||||
--- end
|
||||
--- return table.concat(items, " ")
|
||||
--- A function that accepts a mapping of |diagnostic-severity| to the number of
|
||||
--- diagnostics of the corresponding severity (only those severity levels that
|
||||
--- have at least 1 diagnostic) and returns a 'statusline' component.
|
||||
--- In this case highlights must be applied by the user in the `format` function.
|
||||
--- Example:
|
||||
--- ```lua
|
||||
--- local signs = {
|
||||
--- [vim.diagnostic.severity.ERROR] = "A",
|
||||
--- -- ...
|
||||
--- }
|
||||
--- local hl_map = {
|
||||
--- [vim.diagnostic.severity.ERROR] = 'DiagnosticSignError',
|
||||
--- -- ...
|
||||
--- }
|
||||
--- vim.diagnostic.config({
|
||||
--- status = {
|
||||
--- format = function(severity_counts)
|
||||
--- local items = {}
|
||||
--- for severity in ipairs(vim.diagnostic.severity) do
|
||||
--- local count = severity_counts[severity] or 0
|
||||
--- table.insert(items, ("%%#%s#%s %s"):format(hl_map[severity], signs[severity], count))
|
||||
--- end
|
||||
--- }
|
||||
--- })
|
||||
--- ```
|
||||
--- @field format? table<vim.diagnostic.Severity,string>|(fun(counts:table<vim.diagnostic.Severity,integer>): string)
|
||||
--- return table.concat(items, " ")
|
||||
--- end
|
||||
--- }
|
||||
--- })
|
||||
--- ```
|
||||
--- @field format? (fun(counts:table<vim.diagnostic.Severity,integer>): string)
|
||||
|
||||
--- @class vim.diagnostic.Opts.Underline
|
||||
---
|
||||
@@ -1118,7 +1115,7 @@ function M.status(buf)
|
||||
vim.validate('buf', buf, 'number', true)
|
||||
buf = buf or 0
|
||||
local config = assert(vim.diagnostic.config()).status or {} --- @type vim.diagnostic.Opts.Status
|
||||
vim.validate('config.format', config.format, { 'table', 'function' }, true)
|
||||
vim.validate('config.format', config.format, 'function', true)
|
||||
|
||||
local counts = M.count(buf)
|
||||
local format = config.format
|
||||
@@ -1126,13 +1123,8 @@ function M.status(buf)
|
||||
if type(format) == 'function' then
|
||||
result_str = format(counts)
|
||||
else
|
||||
local signs ---@type table<vim.diagnostic.Severity, string>
|
||||
if type(format) == 'table' then
|
||||
signs = format
|
||||
else
|
||||
signs = M._config.get_resolved_options(vim.diagnostic.config(), nil, buf).signs.text
|
||||
or default_status_signs
|
||||
end
|
||||
local signs = M._config.get_resolved_options(vim.diagnostic.config(), nil, buf).signs.text
|
||||
or default_status_signs
|
||||
result_str = vim
|
||||
.iter(pairs(counts))
|
||||
:map(function(level, value)
|
||||
|
||||
Reference in New Issue
Block a user