nvim/diagnostic: cycle diagnostic layout

credit: mrcjkb
This commit is contained in:
Primrose 2025-07-20 10:58:22 +02:00
parent 6fc31978fc
commit c51141de08
Signed by: primrose
GPG key ID: 4E887A4CA9714ADA

View file

@ -44,6 +44,40 @@ vim.diagnostic.config {
},
}
do
local index = 1
---@type vim.diagnostic.Opts[]
local modes = {
{ virtual_text = false, virtual_lines = false },
{
virtual_text = false,
virtual_lines = {
current_line = true,
severity = {
vim.diagnostic.severity.ERROR,
vim.diagnostic.severity.WARN,
},
},
},
{ virtual_text = true, virtual_lines = false },
}
---@param direction 'forward' | 'backward'
local function cycle_diagnostic_modes(direction)
if direction == "forward" then
index = (index % #modes) + 1
else
index = (index - 2 + #modes) % #modes + 1
end
vim.diagnostic.config(modes[index])
end
vim.keymap.set("n", "]d", function() cycle_diagnostic_modes("forward") end)
vim.keymap.set("n", "[d", function() cycle_diagnostic_modes("backward") end)
end
-- Helix style border
local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview
function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...)