Skip to content

Commit

Permalink
feat(diagnostics): added support for diagnostics signs on Neovim >= 0…
Browse files Browse the repository at this point in the history
….10.0. Fixes #369, fixes #389
  • Loading branch information
folke committed May 30, 2024
1 parent bd8bfc8 commit 6303740
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lua/trouble/format.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,24 @@ M.formatters = {
if not vim.diagnostic.severity[severity] then
return
end
if type(severity) == "string" then
severity = vim.diagnostic.severity[severity:upper()] or vim.diagnostic.severity.ERROR
end
local name = Util.camel(vim.diagnostic.severity[severity]:lower())
local sign = vim.fn.sign_getdefined("DiagnosticSign" .. name)[1]
return sign and { text = sign.text, hl = sign.texthl } or { text = name or ctx.value }
if vim.fn.has("nvim-0.10.0") == 1 then
local config = vim.diagnostic.config() or {}
if config.signs == nil or type(config.signs) == "boolean" then
return { text = name:sub(1, 1), hl = "DiagnosticSign" .. name }
end
local signs = config.signs or {}
if type(signs) == "function" then
signs = signs(0, 0) --[[@as vim.diagnostic.Opts.Signs]]
end
return { text = signs.text and signs.text[severity] or name:sub(1, 1), hl = "DiagnosticSign" .. name }
else
local sign = vim.fn.sign_getdefined("DiagnosticSign" .. name)[1]
return sign and { text = sign.text, hl = sign.texthl } or { text = name } or nil
end
end,
file_icon = function(ctx)
local item = ctx.item --[[@as Diagnostic|trouble.Item]]
Expand Down

0 comments on commit 6303740

Please sign in to comment.