B:BD[
4.25719586] → [
4.25719586:25721656]
-- -- PATCH: override all diagnostic highlights to be severity based
-- -- to mitigate severity being ignored in the special cases of DiagnosticDeprecated and DiagnosticUnnecessary
-- --
-- -- foollow relevant issues:
-- -- #26796 (nvim) https://github.com/neovim/neovim/issues/26796#issuecomment-3236801970
-- -- #1677 (kickstart.nvim)
-- -- #1550 (kickstart.nvim)
-- --
-- Create namespace for our custom highlights
local ns_id = vim.api.nvim_create_namespace('diagnostic_text_highlight')
-- Function to apply highlights to diagnostic ranges
local function highlight_diagnostic_text()
-- Clear previous highlights
vim.api.nvim_buf_clear_namespace(0, ns_id, 0, -1)
-- Get diagnostics for current buffer
local diagnostics = vim.diagnostic.get(0)
for _, diagnostic in ipairs(diagnostics) do
local severity = diagnostic.severity
local start_line = diagnostic.lnum
local start_col = diagnostic.col
local end_line = diagnostic.end_lnum or start_line
local end_col = diagnostic.end_col or (start_col + 1)
-- Choose highlight group based on severity
local hl_group
if severity == vim.diagnostic.severity.ERROR then
hl_group = 'DiagnosticError'
elseif severity == vim.diagnostic.severity.WARN then
hl_group = 'DiagnosticWarn'
elseif severity == vim.diagnostic.severity.INFO then
hl_group = 'DiagnosticInfo'
elseif severity == vim.diagnostic.severity.HINT then
hl_group = 'DiagnosticHint'
end
-- Apply highlight to the specific range
if hl_group then
vim.highlight.range(
0, -- buffer (0 = current)
ns_id, -- namespace
hl_group, -- highlight group
{ start_line, start_col }, -- start position
{ end_line, end_col } -- end position
)
end
end
-- PATCH:
-- The built-in underline handler applies tag highlights (DiagnosticUnnecessary,
-- DiagnosticDeprecated) at the same priority as severity highlights, with tags
-- winning by application order. We pass copies with _tags stripped so only the
-- severity highlight is applied.
-- Upstream: https://github.com/neovim/neovim/issues/26796
local orig_underline = vim.diagnostic.handlers.underline
vim.diagnostic.handlers.underline = {
show = function(namespace, bufnr, diagnostics, opts)
local stripped = {}
for _, d in ipairs(diagnostics) do
if d._tags then
local copy = vim.tbl_extend('keep', {}, d)
copy._tags = nil
stripped[#stripped + 1] = copy
else
stripped[#stripped + 1] = d