nvim-config/lua/diagnostic-conf.lua
2025-08-10 20:24:22 +00:00

63 lines
1.6 KiB
Lua
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local diagnostic = vim.diagnostic
local api = vim.api
-- Global config for diagnostic
diagnostic.config {
underline = false,
virtual_text = false,
virtual_lines = false,
signs = {
text = {
[diagnostic.severity.ERROR] = "🆇",
[diagnostic.severity.WARN] = "⚠️",
[diagnostic.severity.INFO] = "",
[diagnostic.severity.HINT] = "",
},
},
severity_sort = true,
float = {
source = true,
header = "Diagnostics:",
prefix = " ",
border = "single",
},
}
-- Set quickfix list from diagnostics in a certain buffer, not the whole workspace
local set_qflist = function(buf_num, severity)
local diagnostics = nil
diagnostics = diagnostic.get(buf_num, { severity = severity })
local qf_items = diagnostic.toqflist(diagnostics)
vim.fn.setqflist({}, " ", { title = "Diagnostics", items = qf_items })
vim.cmd([[copen]])
end
vim.keymap.set("n", "<space>qw", diagnostic.setqflist, { desc = "Put window diagnostics to qf" })
vim.keymap.set("n", "<space>qb", function()
set_qflist(0)
end, { desc = "Put buffer diagnostics to qf" })
-- Automatically show diagnostic in float win for current line
api.nvim_create_autocmd("CursorHold", {
pattern = "*",
callback = function()
if #vim.diagnostic.get(0) == 0 then
return
end
if not vim.b.diagnostics_pos then
vim.b.diagnostics_pos = { nil, nil }
end
local cursor_pos = api.nvim_win_get_cursor(0)
if not vim.deep_equal(cursor_pos, vim.b.diagnostics_pos) then
diagnostic.open_float { width = 100 }
end
vim.b.diagnostics_pos = cursor_pos
end,
})