Skip to content

Commit

Permalink
fix(diagnostics): custom format for code. Fixes #508
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jun 14, 2024
1 parent e0b35a2 commit ada78fa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions lua/trouble/config/highlights.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ M.colors = {
Directory = "Directory",
IconDirectory = "Special",
Source = "Comment",
Code = "Special",
Pos = "LineNr",
Count = "TabLineSel",

Expand Down
9 changes: 9 additions & 0 deletions lua/trouble/format.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ M.formatters = {
text = "[" .. ctx.item.pos[1] .. ", " .. (ctx.item.pos[2] + 1) .. "]",
}
end,
code = function(ctx)
if not ctx.item.code then
return
end
return {
text = "(" .. ctx.item.code .. ")",
hl = "TroubleCode",
}
end,
severity = function(ctx)
local severity = ctx.item.severity or vim.diagnostic.severity.ERROR
local name = vim.diagnostic.severity[severity] or "OTHER"
Expand Down
2 changes: 1 addition & 1 deletion lua/trouble/sources/diagnostics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ M.config = {
{ "filename", format = "{file_icon} {basename} {count}" },
},
sort = { "severity", "filename", "pos", "message" },
format = "{severity_icon} {message:md} {item.source} ({code}) {pos}",
format = "{severity_icon} {message:md} {item.source} {code} {pos}",
-- filter = {
-- ["not"] = {
-- any = {
Expand Down

0 comments on commit ada78fa

Please sign in to comment.