From 7bd2e1504d0bf3fc9c97faa125949c3fd97a61d0 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 2 May 2023 21:31:06 +0100 Subject: [PATCH] home: vim: lua: lsp: customize diagnostics display --- home/vim/lua/ambroisie/lsp.lua | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/home/vim/lua/ambroisie/lsp.lua b/home/vim/lua/ambroisie/lsp.lua index f935c2f..254d243 100644 --- a/home/vim/lua/ambroisie/lsp.lua +++ b/home/vim/lua/ambroisie/lsp.lua @@ -34,8 +34,32 @@ M.on_attach = function(client, bufnr) utils.dump(vim.lsp.buf.list_workspace_folders()) end - local function show_line_diagnostics() - vim.diagnostic.open_float(nil, { scope="line" }) + local function cycle_diagnostics_display() + -- Cycle from: + -- * nothing displayed + -- * single diagnostic at the end of the line (`virtual_text`) + -- * full diagnostics using virtual text (`virtual_lines`) + local text = vim.diagnostic.config().virtual_text + local lines = vim.diagnostic.config().virtual_lines + + -- Text -> Lines transition + if text then + text = false + lines = true + -- Lines -> Nothing transition + elseif lines then + text = false + lines = false + -- Nothing -> Text transition + else + text = true + lines = false + end + + vim.diagnostic.config({ + virtual_text = text, + virtual_lines = lines, + }) end local function show_buffer_diagnostics() @@ -53,7 +77,7 @@ M.on_attach = function(client, bufnr) ["c"] = { name = "Code", a = { vim.lsp.buf.code_action, "Code actions" }, - d = { show_line_diagnostics, "Show line diagnostics" }, + d = { cycle_diagnostics_display, "Cycle diagnostics display" }, D = { show_buffer_diagnostics, "Show buffer diagnostics" }, r = { vim.lsp.buf.rename, "Rename symbol" }, s = { vim.lsp.buf.signature_help, "Show signature" },