nvim/lua/plugins/diagnostics.lua

122 lines
3 KiB
Lua

local M = {
"stevearc/quicker.nvim",
event = "VimEnter",
dependencies = { "neovim/nvim-lspconfig" },
}
local icons = {
Error = "",
Warning = "",
Information = "",
Hint = "󰌶",
Note = "",
}
-- Map severity to icon
local function get_icon(severity)
local severity_name = vim.diagnostic.severity[severity]
return icons[severity_name] or ""
end
M.init = function()
-- Define diagnostic signs
local severity_names = { "ERROR", "WARN", "INFO", "HINT" }
for _, name in ipairs(severity_names) do
local severity = vim.diagnostic.severity[name]
local sign_name = "DiagnosticSign" .. name
vim.fn.sign_define(sign_name, { text = get_icon(severity), texthl = sign_name })
end
-- Highlight diagnostic signs
vim.cmd([[
highlight DiagnosticSignError guifg=#f7768e gui=bold
highlight DiagnosticSignWarn guifg=#e0af68 gui=bold
highlight DiagnosticSignInfo guifg=#7dcfff gui=bold
highlight DiagnosticSignHint guifg=#9ece6a gui=bold
]])
end
-- Cycle through quickfix items
local function cycle_qf(direction)
local qf = vim.fn.getqflist({ size = 0, idx = 0 })
if qf.size == 0 then
return
end
if direction == "next" then
vim.cmd(qf.idx == qf.size and "cfirst" or "cnext")
else
vim.cmd(qf.idx == 1 and "clast" or "cprev")
end
end
function M.config()
vim.diagnostic.config({
virtual_text = {
prefix = "",
format = function(d)
return string.format("%s %s", get_icon(d.severity), d.message)
end,
},
underline = true,
update_in_insert = false,
signs = {
active = true,
text = {
[vim.diagnostic.severity.ERROR] = icons.Error,
[vim.diagnostic.severity.WARN] = icons.Warning,
[vim.diagnostic.severity.INFO] = icons.Information,
[vim.diagnostic.severity.HINT] = icons.Hint,
},
},
float = {
focusable = true,
style = "minimal",
border = "rounded",
source = true,
format = function(d)
local severity_name = vim.diagnostic.severity[d.severity]
return string.format("%s %s: %s", get_icon(d.severity), severity_name:lower(), d.message)
end,
},
severity_sort = true,
})
-- Quicker setup
require("quicker").setup({
keys = {
{
">",
function()
require("quicker").expand({ before = 2, after = 2, add_to_existing = true })
end,
desc = "Expand quickfix context",
},
{
"<",
function()
require("quicker").collapse()
end,
desc = "Collapse quickfix context",
},
},
type_icons = {
E = icons.Error .. " ",
W = icons.Warning .. " ",
I = icons.Information .. " ",
N = icons.Note,
H = icons.Hint .. " ",
},
})
-- Quickfix navigation mappings
nmap("<a-j>", function()
cycle_qf("next")
end, { desc = "Next quickfix item (cycles)" })
nmap("<a-k>", function()
cycle_qf("prev")
end, { desc = "Previous quickfix item (cycles)" })
end
return M