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, ...)