mirror of
https://github.com/neovim/neovim.git
synced 2026-05-26 14:58:28 +00:00
feat(diagnostic)!: deprecate format as a table #39603
This commit is contained in:
@@ -672,36 +672,33 @@ Lua module: vim.diagnostic *diagnostic-api*
|
||||
*vim.diagnostic.Opts.Status*
|
||||
|
||||
Fields: ~
|
||||
• {format}? (`table<vim.diagnostic.Severity,string>|(fun(counts:table<vim.diagnostic.Severity,integer>): string)`)
|
||||
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, " ")
|
||||
end
|
||||
}
|
||||
})
|
||||
• {format}? (`fun(counts:table<vim.diagnostic.Severity,integer>): string`)
|
||||
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
|
||||
return table.concat(items, " ")
|
||||
end
|
||||
}
|
||||
})
|
||||
<
|
||||
|
||||
*vim.diagnostic.Opts.Underline*
|
||||
|
||||
@@ -73,7 +73,8 @@ API
|
||||
|
||||
DIAGNOSTICS
|
||||
|
||||
• todo
|
||||
• `vim.diagnostic.Opts.Status.format` no longer accepts the table mapping
|
||||
from severity to text. Use `vim.diagnostic.Opts.Signs.text` instead.
|
||||
|
||||
EDITOR
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -4219,11 +4219,11 @@ describe('vim.diagnostic', function()
|
||||
)
|
||||
end)
|
||||
|
||||
it('uses text from diagnostic.config().status.format[severity]', function()
|
||||
it('uses text from diagnostic.config().signs.text[severity]', function()
|
||||
local result = exec_lua(function()
|
||||
vim.diagnostic.config({
|
||||
status = {
|
||||
format = {
|
||||
signs = {
|
||||
text = {
|
||||
[vim.diagnostic.severity.ERROR] = '⨯',
|
||||
[vim.diagnostic.severity.WARN] = '⚠︎',
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user