nvim-config/lua/triimd/diagnostics.lua
2025-10-24 17:13:50 +03:00

43 lines
1.2 KiB
Lua

-- Diagnostics
local special_sources = {
lua_ls = 'lua',
}
vim.diagnostic.config({
underline = true,
severity_sort = true,
virtual_text = {
format = function(diagnostic)
local src = diagnostic.source and (special_sources[diagnostic.source] or diagnostic.source)
if src then
return string.format('%s: %s', src, diagnostic.message)
end
return diagnostic.message
end,
},
float = {
border = 'rounded',
header = '',
format = function(diagnostic)
local src = diagnostic.source and (special_sources[diagnostic.source] or diagnostic.source)
if src then
return string.format('%s: %s', src, diagnostic.message)
end
return diagnostic.message
end,
},
})
-- Override the virtual text diagnostic handler so that the most severe diagnostic is shown first.
local show_handler = vim.diagnostic.handlers.virtual_text.show
assert(show_handler)
local hide_handler = vim.diagnostic.handlers.virtual_text.hide
vim.diagnostic.handlers.virtual_text = {
show = function(ns, bufnr, diagnostics, opts)
table.sort(diagnostics, function(diag1, diag2)
return diag1.severity > diag2.severity
end)
return show_handler(ns, bufnr, diagnostics, opts)
end,
hide = hide_handler,
}