Skip to content

Commit

Permalink
fix: added compatibility to retrieve signs from vim.diagnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Oct 22, 2021
1 parent 51dd917 commit dab82ef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lua/trouble/providers/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function M.get_signs()
for _, v in pairs(util.severity) do
-- pcall to catch entirely unbound or cleared out sign hl group
local status, sign = pcall(function()
return vim.trim(vim.fn.sign_getdefined("LspDiagnosticsSign" .. v)[1].text)
return vim.trim(vim.fn.sign_getdefined(util.get_severity_label(v, "Sign"))[1].text)
end)
if not status then
sign = v:sub(1, 1)
Expand Down
17 changes: 17 additions & 0 deletions lua/trouble/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ M.severity = {
[4] = "Hint",
}

-- returns a hl or sign label for the givin severity and type
-- correctly handles new names introduced in vim.diagnostic
function M.get_severity_label(severity, type)
local label = severity
local prefix = "LspDiagnostics" .. (type or "Default")

if vim.diagnostic then
prefix = type and ("Diagnostic" .. type) or "Diagnostic"
label = ({
Warning = "Warn",
Information = "Info",
})[severity] or severity
end

return prefix .. label
end

-- based on the Telescope diagnostics code
-- see https://github.com/nvim-telescope/telescope.nvim/blob/0d6cd47990781ea760dd3db578015c140c7b9fa7/lua/telescope/utils.lua#L85

Expand Down

0 comments on commit dab82ef

Please sign in to comment.