Skip to content

Commit 5597965

Browse files
committed
feat(diagnostic): prefer the signs from vim.diagnostic.config()
Using vim.fn.sign_define for diagnostic signs is deprecated. This commit will still fall back on those deprecated sign definitions, if the new ones created via `vim.diagnostic.config()` are not defined. This code is largely taken from #3146 with minor adjustments to actually make it work this time.
1 parent b4da76b commit 5597965

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

lua/telescope/make_entry.lua

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,19 +1139,32 @@ end
11391139
function make_entry.gen_from_diagnostics(opts)
11401140
opts = opts or {}
11411141

1142+
local diagnostic_config = vim.diagnostic.config() or {}
1143+
local diagnostic_signs = {}
1144+
if type(diagnostic_config.signs) == "table" then
1145+
diagnostic_signs = diagnostic_config.signs.text or {}
1146+
end
1147+
11421148
local type_diagnostic = vim.diagnostic.severity
11431149
local signs = (function()
11441150
if opts.no_sign then
11451151
return
11461152
end
11471153
local signs = {}
1148-
for _, severity in ipairs(type_diagnostic) do
1149-
local status, sign = pcall(function()
1150-
-- only the first char is upper all others are lowercalse
1151-
return vim.trim(vim.fn.sign_getdefined("DiagnosticSign" .. severity:lower():gsub("^%l", string.upper))[1].text)
1152-
end)
1153-
if not status then
1154-
sign = severity:sub(1, 1)
1154+
for num, severity in ipairs(type_diagnostic) do
1155+
local sign = diagnostic_signs[num]
1156+
if not sign then
1157+
local status
1158+
status, sign = pcall(function()
1159+
-- only the first char is upper all others are lowercase
1160+
return vim.trim(
1161+
vim.fn.sign_getdefined("DiagnosticSign" .. severity:lower():gsub("^%l", string.upper))[1].text
1162+
)
1163+
end)
1164+
1165+
if not status then
1166+
sign = severity:sub(1, 1)
1167+
end
11551168
end
11561169
signs[severity] = sign
11571170
end

0 commit comments

Comments
 (0)