mirror of
https://github.com/neovim/neovim.git
synced 2025-12-11 17:12:40 +00:00
feat(diagnostic): config.status #36693
Problem: `diagnostic.status()` is configured via `config.signs`, but users may want diagnostics only in statusline, not in the gutter (signs). Solution: Add `config.status`.
This commit is contained in:
@@ -553,6 +553,9 @@ Lua module: vim.diagnostic *diagnostic-api*
|
|||||||
• {float}? (`boolean|vim.diagnostic.Opts.Float|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.Float`)
|
• {float}? (`boolean|vim.diagnostic.Opts.Float|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.Float`)
|
||||||
Options for floating windows. See
|
Options for floating windows. See
|
||||||
|vim.diagnostic.Opts.Float|.
|
|vim.diagnostic.Opts.Float|.
|
||||||
|
• {status}? (`vim.diagnostic.Opts.Status`) Options for the
|
||||||
|
statusline component. See
|
||||||
|
|vim.diagnostic.Opts.Status|.
|
||||||
• {update_in_insert}? (`boolean`, default: `false`) Update diagnostics
|
• {update_in_insert}? (`boolean`, default: `false`) Update diagnostics
|
||||||
in Insert mode (if `false`, diagnostics are
|
in Insert mode (if `false`, diagnostics are
|
||||||
updated on |InsertLeave|)
|
updated on |InsertLeave|)
|
||||||
@@ -665,6 +668,13 @@ Lua module: vim.diagnostic *diagnostic-api*
|
|||||||
|diagnostic-severity| to the highlight group used for the
|
|diagnostic-severity| to the highlight group used for the
|
||||||
whole line the sign is placed in.
|
whole line the sign is placed in.
|
||||||
|
|
||||||
|
*vim.diagnostic.Opts.Status*
|
||||||
|
|
||||||
|
Fields: ~
|
||||||
|
• {text}? (`table<vim.diagnostic.Severity,string>`) A table mapping
|
||||||
|
|diagnostic-severity| to the text to use for each severity
|
||||||
|
section.
|
||||||
|
|
||||||
*vim.diagnostic.Opts.Underline*
|
*vim.diagnostic.Opts.Underline*
|
||||||
|
|
||||||
Fields: ~
|
Fields: ~
|
||||||
@@ -1023,9 +1033,9 @@ status({bufnr}) *vim.diagnostic.status()*
|
|||||||
Returns formatted string with diagnostics for the current buffer. The
|
Returns formatted string with diagnostics for the current buffer. The
|
||||||
severities with 0 diagnostics are left out. Example `E:2 W:3 I:4 H:5`
|
severities with 0 diagnostics are left out. Example `E:2 W:3 I:4 H:5`
|
||||||
|
|
||||||
To customise appearance, set diagnostic signs text with >lua
|
To customise appearance, set diagnostic text for each severity with >lua
|
||||||
vim.diagnostic.config({
|
vim.diagnostic.config({
|
||||||
signs = { text = { [vim.diagnostic.severity.ERROR] = 'e', ... } }
|
status = { text = { [vim.diagnostic.severity.ERROR] = 'e', ... } }
|
||||||
})
|
})
|
||||||
<
|
<
|
||||||
|
|
||||||
|
|||||||
@@ -94,6 +94,9 @@ end
|
|||||||
--- Options for floating windows. See |vim.diagnostic.Opts.Float|.
|
--- Options for floating windows. See |vim.diagnostic.Opts.Float|.
|
||||||
--- @field float? boolean|vim.diagnostic.Opts.Float|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.Float
|
--- @field float? boolean|vim.diagnostic.Opts.Float|fun(namespace: integer, bufnr:integer): vim.diagnostic.Opts.Float
|
||||||
---
|
---
|
||||||
|
--- Options for the statusline component.
|
||||||
|
--- @field status? vim.diagnostic.Opts.Status
|
||||||
|
---
|
||||||
--- Update diagnostics in Insert mode
|
--- Update diagnostics in Insert mode
|
||||||
--- (if `false`, diagnostics are updated on |InsertLeave|)
|
--- (if `false`, diagnostics are updated on |InsertLeave|)
|
||||||
--- (default: `false`)
|
--- (default: `false`)
|
||||||
@@ -184,6 +187,11 @@ end
|
|||||||
--- Overrides the setting from |vim.diagnostic.config()|.
|
--- Overrides the setting from |vim.diagnostic.config()|.
|
||||||
--- @field suffix? string|table|(fun(diagnostic:vim.Diagnostic,i:integer,total:integer): string, string)
|
--- @field suffix? string|table|(fun(diagnostic:vim.Diagnostic,i:integer,total:integer): string, string)
|
||||||
|
|
||||||
|
--- @class vim.diagnostic.Opts.Status
|
||||||
|
---
|
||||||
|
--- A table mapping |diagnostic-severity| to the text to use for each severity section.
|
||||||
|
--- @field text? table<vim.diagnostic.Severity,string>
|
||||||
|
|
||||||
--- @class vim.diagnostic.Opts.Underline
|
--- @class vim.diagnostic.Opts.Underline
|
||||||
---
|
---
|
||||||
--- Only underline diagnostics matching the given
|
--- Only underline diagnostics matching the given
|
||||||
@@ -2887,10 +2895,10 @@ local hl_map = {
|
|||||||
--- The severities with 0 diagnostics are left out.
|
--- The severities with 0 diagnostics are left out.
|
||||||
--- Example `E:2 W:3 I:4 H:5`
|
--- Example `E:2 W:3 I:4 H:5`
|
||||||
---
|
---
|
||||||
--- To customise appearance, set diagnostic signs text with
|
--- To customise appearance, set diagnostic text for each severity with
|
||||||
--- ```lua
|
--- ```lua
|
||||||
--- vim.diagnostic.config({
|
--- vim.diagnostic.config({
|
||||||
--- signs = { text = { [vim.diagnostic.severity.ERROR] = 'e', ... } }
|
--- status = { text = { [vim.diagnostic.severity.ERROR] = 'e', ... } }
|
||||||
--- })
|
--- })
|
||||||
--- ```
|
--- ```
|
||||||
---@param bufnr? integer Buffer number to get diagnostics from.
|
---@param bufnr? integer Buffer number to get diagnostics from.
|
||||||
@@ -2901,7 +2909,7 @@ function M.status(bufnr)
|
|||||||
vim.validate('bufnr', bufnr, 'number', true)
|
vim.validate('bufnr', bufnr, 'number', true)
|
||||||
bufnr = bufnr or 0
|
bufnr = bufnr or 0
|
||||||
local counts = M.count(bufnr)
|
local counts = M.count(bufnr)
|
||||||
local user_signs = vim.tbl_get(M.config() --[[@as vim.diagnostic.Opts]], 'signs', 'text') or {}
|
local user_signs = vim.tbl_get(M.config() --[[@as vim.diagnostic.Opts]], 'status', 'text') or {}
|
||||||
local signs = vim.tbl_extend('keep', user_signs, { 'E', 'W', 'I', 'H' })
|
local signs = vim.tbl_extend('keep', user_signs, { 'E', 'W', 'I', 'H' })
|
||||||
local result_str = vim
|
local result_str = vim
|
||||||
.iter(pairs(counts))
|
.iter(pairs(counts))
|
||||||
|
|||||||
@@ -4097,10 +4097,10 @@ describe('vim.diagnostic', function()
|
|||||||
)
|
)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('uses text from diagnostic.config().signs.text[severity]', function()
|
it('uses text from diagnostic.config().status.text[severity]', function()
|
||||||
local result = exec_lua(function()
|
local result = exec_lua(function()
|
||||||
vim.diagnostic.config({
|
vim.diagnostic.config({
|
||||||
signs = {
|
status = {
|
||||||
text = {
|
text = {
|
||||||
[vim.diagnostic.severity.ERROR] = '⨯',
|
[vim.diagnostic.severity.ERROR] = '⨯',
|
||||||
[vim.diagnostic.severity.WARN] = '⚠︎',
|
[vim.diagnostic.severity.WARN] = '⚠︎',
|
||||||
|
|||||||
Reference in New Issue
Block a user