diagnostics.lua (2668B)
1 ---@diagnostic disable: undefined-global 2 local palette = { 3 err = "#51202A", 4 warn = "#3B3B1B", 5 info = "#1F3342", 6 hint = "#1E2E1E", 7 } 8 9 vim.api.nvim_set_hl(0, "DiagnosticErrorLine", { bg = palette.err, blend = 20 }) 10 vim.api.nvim_set_hl(0, "DiagnosticWarnLine", { bg = palette.warn, blend = 15 }) 11 vim.api.nvim_set_hl(0, "DiagnosticInfoLine", { bg = palette.info, blend = 10 }) 12 vim.api.nvim_set_hl(0, "DiagnosticHintLine", { bg = palette.hint, blend = 10 }) 13 14 vim.api.nvim_set_hl(0, "DapBreakpointSign", { fg = "#FF0000", bg = nil, bold = true }) 15 vim.fn.sign_define("DapBreakpoint", { 16 text = "●", 17 texthl = "DapBreakpointSign", 18 linehl = "", 19 numhl = "", 20 }) 21 22 local sev = vim.diagnostic.severity 23 24 vim.diagnostic.config({ 25 underline = true, 26 severity_sort = true, 27 update_in_insert = false, 28 float = { 29 border = "rounded", 30 source = true, 31 }, 32 signs = { 33 text = { 34 [sev.ERROR] = "E", 35 [sev.WARN] = "W", 36 [sev.INFO] = "I", 37 [sev.HINT] = " ", 38 }, 39 }, 40 virtual_text = { 41 spacing = 4, 42 source = "if_many", 43 prefix = "●", 44 }, 45 linehl = { 46 [sev.ERROR] = "DiagnosticErrorLine", 47 [sev.WARN] = "DiagnosticWarnLine", 48 [sev.INFO] = "DiagnosticInfoLine", 49 [sev.HINT] = "DiagnosticHintLine", 50 }, 51 }) 52 53 local diagnostic_goto = function(next, severity) 54 severity = severity and vim.diagnostic.severity[severity] or nil 55 return function() 56 vim.diagnostic.jump({ count = next and 1 or -1, float = true, severity = severity }) 57 end 58 end 59 60 local map = vim.keymap.set 61 62 map("n", "<leader>h", function() 63 local bufnr = vim.api.nvim_get_current_buf() 64 local enabled = vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }) 65 vim.lsp.inlay_hint.enable(not enabled, { bufnr = bufnr }) 66 vim.notify("Inlay hints " .. (enabled and "OFF" or "ON")) 67 end, { silent = true, desc = "Toggle inlay hints" }) 68 69 map("n", "<leader>d", function() 70 local bufnr = vim.api.nvim_get_current_buf() 71 local enabled = vim.diagnostic.is_enabled({ bufnr = bufnr }) 72 vim.diagnostic.enable(not enabled, { bufnr = bufnr }) 73 vim.notify("Diagnostics " .. (enabled and "OFF" or "ON")) 74 end, { silent = true, desc = "Toggle diagnostics" }) 75 76 map("n", "<C-w>d", vim.diagnostic.open_float, { desc = "Line Diagnostics" }) 77 map("n", "]d", diagnostic_goto(true), { desc = "Next Diagnostic" }) 78 map("n", "[d", diagnostic_goto(false), { desc = "Prev Diagnostic" }) 79 map("n", "]e", diagnostic_goto(true, "ERROR"), { desc = "Next Error" }) 80 map("n", "[e", diagnostic_goto(false, "ERROR"), { desc = "Prev Error" }) 81 map("n", "]w", diagnostic_goto(true, "WARN"), { desc = "Next Warning" }) 82 map("n", "[w", diagnostic_goto(false, "WARN"), { desc = "Prev Warning" })