mirror of
https://github.com/neovim/neovim.git
synced 2026-05-02 12:04:58 +00:00
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:
committed by
GitHub
parent
5d258854a7
commit
2767eac320
@@ -1734,29 +1734,30 @@ M.handlers.underline = {
|
||||
local get_priority = severity_to_extmark_priority(vim.hl.priorities.diagnostics, opts)
|
||||
|
||||
for _, diagnostic in ipairs(diagnostics) do
|
||||
local higroup = underline_highlight_map[diagnostic.severity]
|
||||
local higroups = { underline_highlight_map[diagnostic.severity] }
|
||||
|
||||
if diagnostic._tags then
|
||||
-- TODO(lewis6991): we should be able to stack these.
|
||||
if diagnostic._tags.unnecessary then
|
||||
higroup = 'DiagnosticUnnecessary'
|
||||
table.insert(higroups, 'DiagnosticUnnecessary')
|
||||
end
|
||||
if diagnostic._tags.deprecated then
|
||||
higroup = 'DiagnosticDeprecated'
|
||||
table.insert(higroups, 'DiagnosticDeprecated')
|
||||
end
|
||||
end
|
||||
|
||||
local lines =
|
||||
api.nvim_buf_get_lines(diagnostic.bufnr, diagnostic.lnum, diagnostic.lnum + 1, true)
|
||||
|
||||
vim.hl.range(
|
||||
bufnr,
|
||||
underline_ns,
|
||||
higroup,
|
||||
{ diagnostic.lnum, math.min(diagnostic.col, #lines[1] - 1) },
|
||||
{ diagnostic.end_lnum, diagnostic.end_col },
|
||||
{ priority = get_priority(diagnostic.severity) }
|
||||
)
|
||||
for _, higroup in ipairs(higroups) do
|
||||
vim.hl.range(
|
||||
bufnr,
|
||||
underline_ns,
|
||||
higroup,
|
||||
{ diagnostic.lnum, math.min(diagnostic.col, #lines[1] - 1) },
|
||||
{ diagnostic.end_lnum, diagnostic.end_col },
|
||||
{ priority = get_priority(diagnostic.severity) }
|
||||
)
|
||||
end
|
||||
end
|
||||
save_extmarks(underline_ns, bufnr)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user