feat(diagnostics): stack DiagnosticUnnecessary,DiagnosticDeprecated highlights #36590

Problem: unnecessary and deprecated diagnostics use their own highlight
groups (`DiagnosticUnnecessary` and `DiagnosticDeprecated`) which
override the typical severity-based highlight groups (like
`DiagnosticUnderlineWarn`).

This can be misleading, since diagnostics about unused variables which
are warnings or errors, are shown like comments, since then only the
`DiagnosticUnnecessary` highlight group is used. Users do not see the
more eye-catching red/yellow highlight.

Solution: Instead of overriding the highlight group to
`DiagnosticUnnecessary` or `DiagnosticDeprecated`, set them in addition
to the normal severity-based highlights.
This commit is contained in:
Grzegorz Rozdzialik
2025-11-17 18:37:59 +01:00
committed by GitHub
parent 5d258854a7
commit 2767eac320
2 changed files with 42 additions and 12 deletions

View File

@@ -2023,6 +2023,35 @@ describe('vim.diagnostic', function()
eq('DiagnosticUnderlineInfo', underline_hl)
end)
it(
'shows deprecated and unnecessary highlights in addition to severity-based highlights',
function()
---@type string[]
local result = exec_lua(function()
local diagnostic = _G.make_error('Some error', 0, 0, 0, 0, 'source x')
diagnostic._tags = {
deprecated = true,
unnecessary = true,
}
local diagnostics = { diagnostic }
vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, diagnostics)
local extmarks = _G.get_underline_extmarks(_G.diagnostic_ns)
local hl_groups = vim.tbl_map(function(extmark)
return extmark[4].hl_group
end, extmarks)
return hl_groups
end)
eq({
'DiagnosticDeprecated',
'DiagnosticUnnecessary',
'DiagnosticUnderlineError',
}, result)
end
)
it('can show diagnostic sources in virtual text', function()
local result = exec_lua(function()
local diagnostics = {