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", "qw", diagnostic.setqflist, { desc = "Put window diagnostics to qf" }) vim.keymap.set("n", "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, })