diagnostics.lua 3.1 KB

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