home: vim: lua: lsp: customize diagnostics display

This commit is contained in:
Bruno BELANYI 2023-05-02 21:31:06 +01:00
parent b0f054b1e6
commit 7bd2e1504d

View file

@ -34,8 +34,32 @@ M.on_attach = function(client, bufnr)
utils.dump(vim.lsp.buf.list_workspace_folders()) utils.dump(vim.lsp.buf.list_workspace_folders())
end end
local function show_line_diagnostics() local function cycle_diagnostics_display()
vim.diagnostic.open_float(nil, { scope="line" }) -- 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 end
local function show_buffer_diagnostics() local function show_buffer_diagnostics()
@ -53,7 +77,7 @@ M.on_attach = function(client, bufnr)
["<leader>c"] = { ["<leader>c"] = {
name = "Code", name = "Code",
a = { vim.lsp.buf.code_action, "Code actions" }, 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" }, D = { show_buffer_diagnostics, "Show buffer diagnostics" },
r = { vim.lsp.buf.rename, "Rename symbol" }, r = { vim.lsp.buf.rename, "Rename symbol" },
s = { vim.lsp.buf.signature_help, "Show signature" }, s = { vim.lsp.buf.signature_help, "Show signature" },