backport fix(diagnostic): status() respects config.signs (#39601)

Problem:
`diagnostic.status` only follows the `config.status.format` setting to determine how to display diagnostic signs. However, `signs` can actually also be configured via `config.signs.text`.

Solution:
If the user has set symbols via `config.status.format`, let that determine the content of `signs`; otherwise, use `config.signs.text` for display.

TODO: drop support `type(config.status.format) == 'table'`; users should just configure `config.signs.text` directly.

Co-authored-by: Yi Ming <ofseed@foxmail.com>
This commit is contained in:
Justin M. Keyes
2026-05-06 12:42:02 -04:00
committed by GitHub
parent 70f22713a1
commit 0197461265
6 changed files with 24 additions and 16 deletions

View File

@@ -26,7 +26,7 @@ jobs:
- name: Create backport PR
id: backport
uses: korthout/backport-action@4aaf0e03a94ff0a619c9a511b61aeb42adea5b02 # v4.2.0
uses: korthout/backport-action@7c3f6cd5843cac11bc59a04a1b7699af93261670 # v4.5.0
with:
pull_title: "backport: ${pull_title}"
label_pattern: "^ci:backport ([^ ]+)$"

View File

@@ -31,11 +31,11 @@ jobs:
- uses: ./.github/actions/setup
- name: Initialize CodeQL
uses: github/codeql-action/init@v4.35.1
uses: github/codeql-action/init@v4.35.2
with:
languages: cpp
- run: make
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4.35.1
uses: github/codeql-action/analyze@v4.35.2

View File

@@ -21,4 +21,4 @@ jobs:
persist-credentials: false
- name: Run zizmor
uses: zizmorcore/zizmor-action@71321a20a9ded102f6e9ce5718a2fcec2c4f70d8 # v0.5.2
uses: zizmorcore/zizmor-action@b1d7e1fb5de872772f31590499237e7cce841e8e # v0.5.3

View File

@@ -661,9 +661,9 @@ Lua module: vim.diagnostic *diagnostic-api*
|diagnostic-severity|
• {text}? (`table<vim.diagnostic.Severity,string>`) A table mapping
|diagnostic-severity| to the sign text to display in the
sign column. The default is to use `"E"`, `"W"`, `"I"`,
and `"H"` for errors, warnings, information, and hints,
respectively. Example: >lua
sign column and statusline. The default is to use `"E"`,
`"W"`, `"I"`, and `"H"` for errors, warnings,
information, and hints, respectively. Example: >lua
vim.diagnostic.config({
signs = { text = { [vim.diagnostic.severity.ERROR] = 'E', ... } }
})

View File

@@ -158,6 +158,8 @@ DIAGNOSTICS
enabled or disabled diagnostics.
• |vim.diagnostic.status()| returns a status description of current buffer
diagnostics.
• It uses the severity names defined by the `signs` field of
|vim.diagnostic.config()|, if any.
• |vim.diagnostic.fromqflist()| accepts `opts.merge_lines` to merge multiline
compiler messages.

View File

@@ -313,8 +313,8 @@ end
--- @field priority? integer
---
--- A table mapping |diagnostic-severity| to the sign text to display in the
--- sign column. The default is to use `"E"`, `"W"`, `"I"`, and `"H"` for errors,
--- warnings, information, and hints, respectively. Example:
--- sign column and statusline. The default is to use `"E"`, `"W"`, `"I"`, and `"H"`
--- for errors, warnings, information, and hints, respectively. Example:
--- ```lua
--- vim.diagnostic.config({
--- signs = { text = { [vim.diagnostic.severity.ERROR] = 'E', ... } }
@@ -3028,20 +3028,26 @@ function M.status(bufnr)
bufnr = bufnr or 0
local config = assert(M.config()).status or {}
vim.validate('config.format', config.format, { 'table', 'function' }, true)
local counts = M.count(bufnr)
local format = config.format or default_status_signs
--- @type string
local result_str
if type(format) == 'table' then
local signs = vim.tbl_extend('keep', format, default_status_signs)
local format = config.format
local result_str --- @type string
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
local signs_config = assert(vim.diagnostic.config()).signs
signs = type(signs_config) == 'table' and signs_config.text or default_status_signs
end
result_str = vim
.iter(pairs(counts))
:map(function(severity, count)
return ('%%#%s#%s:%s'):format(hl_map[severity], signs[severity], count)
end)
:join(' ')
elseif type(format) == 'function' then
result_str = format(counts)
end
if result_str:len() > 0 then
result_str = result_str .. '%##'