diagnostics.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. local M = {
  2. "stevearc/quicker.nvim",
  3. -- Set plugin to load on VimEnter instead of FileType qf to ensure diagnostics are configured early
  4. event = { "VimEnter" },
  5. -- Add an explicit dependency for diagnostics loading
  6. dependencies = { "nvim-lspconfig" }, -- Assuming you're using nvim-lspconfig
  7. }
  8. -- Move sign registration outside of the config function to ensure it runs early
  9. local function register_diagnostic_signs()
  10. -- Define diagnostic sign icons
  11. local sign_icons = {
  12. [vim.diagnostic.severity.ERROR] = "󰅙", -- Alternative error symbol
  13. [vim.diagnostic.severity.WARN] = "󱈸", -- Alternative warning
  14. [vim.diagnostic.severity.HINT] = "󰮱", -- Star for hints
  15. [vim.diagnostic.severity.INFO] = "󰋼", -- Info circle
  16. }
  17. -- Register signs explicitly
  18. for severity, icon in pairs(sign_icons) do
  19. local name = "DiagnosticSign" .. vim.diagnostic.severity[severity]
  20. vim.fn.sign_define(name, { text = icon, texthl = name })
  21. end
  22. -- Set sign highlights for better visibility
  23. vim.cmd([[
  24. highlight DiagnosticSignError guifg=#f7768e gui=bold
  25. highlight DiagnosticSignWarn guifg=#e0af68 gui=bold
  26. highlight DiagnosticSignInfo guifg=#7dcfff gui=bold
  27. highlight DiagnosticSignHint guifg=#9ece6a gui=bold
  28. ]])
  29. end
  30. -- This will now be called during setup() which happens at init
  31. M.init = function()
  32. register_diagnostic_signs()
  33. end
  34. local function setup_diagnostic_config()
  35. -- Define prettier diagnostic icons
  36. local diagnostic_icons = {
  37. [vim.diagnostic.severity.ERROR] = "󰅚", -- More prominent error symbol
  38. [vim.diagnostic.severity.WARN] = "󰀦", -- Warning triangle
  39. [vim.diagnostic.severity.HINT] = "󰌵", -- Lightbulb for hints
  40. [vim.diagnostic.severity.INFO] = "󰋽", -- Information symbol
  41. }
  42. -- Configure diagnostics
  43. vim.diagnostic.config({
  44. virtual_text = {
  45. prefix = "●",
  46. suffix = "",
  47. format = function(diagnostic)
  48. local icon = diagnostic_icons[diagnostic.severity] or ""
  49. return string.format("%s %s", icon, diagnostic.message)
  50. end,
  51. },
  52. underline = true, -- Enable underline for better visibility
  53. update_in_insert = false,
  54. signs = {
  55. active = true,
  56. text = {
  57. [vim.diagnostic.severity.ERROR] = "󰅙", -- Alternative error symbol
  58. [vim.diagnostic.severity.WARN] = "󱈸", -- Alternative warning
  59. [vim.diagnostic.severity.HINT] = "󰮱", -- Star for hints
  60. [vim.diagnostic.severity.INFO] = "󰋼", -- Info circle
  61. },
  62. },
  63. float = {
  64. focusable = true,
  65. style = "minimal",
  66. border = "rounded",
  67. source = true,
  68. header = "",
  69. prefix = "",
  70. format = function(diagnostic)
  71. local severity = vim.diagnostic.severity[diagnostic.severity]
  72. local icon = diagnostic_icons[diagnostic.severity] or ""
  73. return string.format("%s %s: %s", icon, severity:lower(), diagnostic.message)
  74. end,
  75. },
  76. severity_sort = true,
  77. })
  78. end
  79. local function cycle_qf(cmd)
  80. local qf_list_empty = vim.fn.getqflist({ size = 0 }).size == 0
  81. if qf_list_empty then
  82. return
  83. end
  84. local current_qf = vim.fn.getqflist({ idx = 0 }).idx
  85. local qf_size = vim.fn.getqflist({ size = 0 }).size
  86. if cmd == "next" then
  87. if current_qf == qf_size then
  88. vim.cmd("cfirst")
  89. else
  90. vim.cmd("cnext")
  91. end
  92. elseif cmd == "prev" then
  93. if current_qf == 1 then
  94. vim.cmd("clast")
  95. else
  96. vim.cmd("cprev")
  97. end
  98. end
  99. end
  100. function M.config()
  101. local opts = {
  102. keys = {
  103. {
  104. ">",
  105. function()
  106. require("quicker").expand({ before = 2, after = 2, add_to_existing = true })
  107. end,
  108. desc = "Expand quickfix context",
  109. },
  110. {
  111. "<",
  112. function()
  113. require("quicker").collapse()
  114. end,
  115. desc = "Collapse quickfix context",
  116. },
  117. },
  118. type_icons = {
  119. E = "󰅚 ", -- Error
  120. W = "󰀦 ", -- Warning
  121. I = "󰋽 ", -- Info
  122. N = "󰎚 ", -- Note
  123. H = "󰌵 ", -- Hint
  124. },
  125. }
  126. require("quicker").setup(opts)
  127. setup_diagnostic_config()
  128. -- Replace the existing mappings with the cycling versions
  129. nmap("<a-j>", function()
  130. cycle_qf("next")
  131. end, { desc = "Next quickfix item (cycles)" })
  132. nmap("<a-k>", function()
  133. cycle_qf("prev")
  134. end, { desc = "Previous quickfix item (cycles)" })
  135. end
  136. return M