diagnostics.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. local M = {
  2. "stevearc/quicker.nvim",
  3. event = "VimEnter",
  4. dependencies = { "neovim/nvim-lspconfig" },
  5. }
  6. local icons = {
  7. Error = "",
  8. Warning = "",
  9. Information = "",
  10. Hint = "󰌶",
  11. Note = " ",
  12. }
  13. -- Map severity to icon
  14. local function get_icon(severity)
  15. local severity_name = vim.diagnostic.severity[severity]
  16. return icons[severity_name] or ""
  17. end
  18. M.init = function()
  19. -- Define diagnostic signs
  20. local severity_names = { "ERROR", "WARN", "INFO", "HINT" }
  21. for _, name in ipairs(severity_names) do
  22. local severity = vim.diagnostic.severity[name]
  23. local sign_name = "DiagnosticSign" .. name
  24. vim.fn.sign_define(sign_name, { text = get_icon(severity), texthl = sign_name })
  25. end
  26. -- Highlight diagnostic signs
  27. vim.cmd([[
  28. highlight DiagnosticSignError guifg=#f7768e gui=bold
  29. highlight DiagnosticSignWarn guifg=#e0af68 gui=bold
  30. highlight DiagnosticSignInfo guifg=#7dcfff gui=bold
  31. highlight DiagnosticSignHint guifg=#9ece6a gui=bold
  32. ]])
  33. end
  34. -- Cycle through quickfix items
  35. local function cycle_qf(direction)
  36. local qf = vim.fn.getqflist({ size = 0, idx = 0 })
  37. if qf.size == 0 then
  38. return
  39. end
  40. if direction == "next" then
  41. vim.cmd(qf.idx == qf.size and "cfirst" or "cnext")
  42. else
  43. vim.cmd(qf.idx == 1 and "clast" or "cprev")
  44. end
  45. end
  46. function M.config()
  47. vim.diagnostic.config({
  48. virtual_text = {
  49. prefix = "●",
  50. format = function(d)
  51. return string.format("%s %s", get_icon(d.severity), d.message)
  52. end,
  53. },
  54. underline = true,
  55. update_in_insert = false,
  56. signs = {
  57. active = true,
  58. text = {
  59. [vim.diagnostic.severity.ERROR] = icons.Error,
  60. [vim.diagnostic.severity.WARN] = icons.Warning,
  61. [vim.diagnostic.severity.INFO] = icons.Information,
  62. [vim.diagnostic.severity.HINT] = icons.Hint,
  63. },
  64. },
  65. float = {
  66. focusable = true,
  67. style = "minimal",
  68. border = "rounded",
  69. source = true,
  70. format = function(d)
  71. local severity_name = vim.diagnostic.severity[d.severity]
  72. return string.format("%s %s: %s", get_icon(d.severity), severity_name:lower(), d.message)
  73. end,
  74. },
  75. severity_sort = true,
  76. })
  77. -- Quicker setup
  78. require("quicker").setup({
  79. keys = {
  80. {
  81. ">",
  82. function()
  83. require("quicker").expand({ before = 2, after = 2, add_to_existing = true })
  84. end,
  85. desc = "Expand quickfix context",
  86. },
  87. {
  88. "<",
  89. function()
  90. require("quicker").collapse()
  91. end,
  92. desc = "Collapse quickfix context",
  93. },
  94. },
  95. type_icons = {
  96. E = icons.Error .. " ",
  97. W = icons.Warning .. " ",
  98. I = icons.Information .. " ",
  99. N = icons.Note,
  100. H = icons.Hint .. " ",
  101. },
  102. })
  103. -- Quickfix navigation mappings
  104. nmap("<a-j>", function()
  105. cycle_qf("next")
  106. end, { desc = "Next quickfix item (cycles)" })
  107. nmap("<a-k>", function()
  108. cycle_qf("prev")
  109. end, { desc = "Previous quickfix item (cycles)" })
  110. end
  111. return M