From 95b2ee07cc30816161b3b540475b9e345d64fb9a Mon Sep 17 00:00:00 2001 From: David Thievon Date: Wed, 24 Sep 2025 17:13:41 +0200 Subject: [PATCH] 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 https://github.com/nvim-telescope/telescope.nvim/pull/3146 with minor adjustments to actually make it work this time. --- lua/telescope/make_entry.lua | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index 0b1a6e5d6c..2c48f411fe 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -1139,19 +1139,32 @@ end function make_entry.gen_from_diagnostics(opts) opts = opts or {} + local diagnostic_config = vim.diagnostic.config() or {} + local diagnostic_signs = {} + if type(diagnostic_config.signs) == "table" then + diagnostic_signs = diagnostic_config.signs.text or {} + end + local type_diagnostic = vim.diagnostic.severity local signs = (function() if opts.no_sign then return end local signs = {} - for _, severity in ipairs(type_diagnostic) do - local status, sign = pcall(function() - -- only the first char is upper all others are lowercalse - return vim.trim(vim.fn.sign_getdefined("DiagnosticSign" .. severity:lower():gsub("^%l", string.upper))[1].text) - end) - if not status then - sign = severity:sub(1, 1) + for num, severity in ipairs(type_diagnostic) do + local sign = diagnostic_signs[num] + if not sign then + local status + status, sign = pcall(function() + -- only the first char is upper all others are lowercase + return vim.trim( + vim.fn.sign_getdefined("DiagnosticSign" .. severity:lower():gsub("^%l", string.upper))[1].text + ) + end) + + if not status then + sign = severity:sub(1, 1) + end end signs[severity] = sign end