From c51141de082d5e175095d871fff6e378fbea5fab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9ana=20=E6=B1=9F?= Date: Sun, 20 Jul 2025 10:58:22 +0200 Subject: [PATCH] nvim/diagnostic: cycle diagnostic layout credit: mrcjkb --- .config/nvim/plugin/lsp.lua | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/.config/nvim/plugin/lsp.lua b/.config/nvim/plugin/lsp.lua index 9e5466b8..9e43fd7d 100644 --- a/.config/nvim/plugin/lsp.lua +++ b/.config/nvim/plugin/lsp.lua @@ -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, ...)