Adjusted diagnostic config

This commit is contained in:
Dreaded_X 2025-05-28 17:58:57 +02:00
parent 1ff53112ae
commit 66d933cbb3
Signed by: Dreaded_X
GPG Key ID: 5A0CBFE3C3377FAA
2 changed files with 14 additions and 24 deletions

View File

@ -64,19 +64,7 @@ vim.api.nvim_create_autocmd("LspAttach", {
vim.keymap.set("n", "]d", function() vim.keymap.set("n", "]d", function()
vim.diagnostic.jump({ count = 1 }) vim.diagnostic.jump({ count = 1 })
end, { desc = "Go to next diagnostic message" }) end, { desc = "Go to next diagnostic message" })
-- vim.keymap.set("n", "<leader>e", vim.diagnostic.open_float, { desc = "Open floating diagnostic message" }) vim.keymap.set("n", "<leader>e", vim.diagnostic.open_float, { desc = "Open floating diagnostic message" })
vim.keymap.set("n", "<leader>e", function()
if vim.diagnostic.config().virtual_lines then
vim.diagnostic.config({ virtual_lines = false })
else
vim.diagnostic.config({
virtual_lines = {
current_line = true,
format = vim.diagnostic.config().virtual_text.format,
},
})
end
end, { desc = "Show virtual diagnostic line" })
-- Helpers -- Helpers
vim.keymap.set("n", "<leader>rn", function() vim.keymap.set("n", "<leader>rn", function()
@ -132,10 +120,3 @@ vim.api.nvim_create_autocmd("LspAttach", {
end end
end, end,
}) })
--
vim.api.nvim_create_autocmd("CursorMoved", {
callback = function()
vim.diagnostic.config({ virtual_lines = false })
end,
})

View File

@ -82,10 +82,19 @@ vim.diagnostic.config({
[vim.diagnostic.severity.INFO] = diagnostic.info, [vim.diagnostic.severity.INFO] = diagnostic.info,
}, },
}, },
virtual_text = { float = {
virt_text_pos = "eol_right_align", severity_sort = false,
format = function(d) header = "",
return ("%s [%s]"):format(d.message, d.source) suffix = function(d)
local code = d.code and string.format(" (%s)", d.code) or ""
return string.format("%s [%s]", code, d.source), "NormalFloat"
end, end,
}, },
virtual_text = {
prefix = function(d)
return vim.diagnostic.config().signs.text[d.severity]
end,
virt_text_pos = "eol_right_align",
},
}) })