Skip to content

Commit

Permalink
feat: added explicit support for mini.icons
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jul 3, 2024
1 parent 0fe430e commit 42dcb58
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions lua/trouble/format.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ function M.default_hl(source, field)
return hl
end

---@type (fun(file: string, ext: string): string, string)[]
local icons = {
function(file)
return require("mini.icons").get("file", file)
end,
function(file, ext)
return require("nvim-web-devicons").get_icon(file, ext, { default = true })
end,
}
function M.get_icon(file, ext)
while #icons > 0 do
local ok, icon, hl = pcall(icons[1], file, ext)
if ok then
return icon, hl
end
table.remove(icons, 1)
end
end

---@param fn trouble.Formatter
---@param field string
function M.cached_formatter(fn, field)
Expand Down Expand Up @@ -95,14 +114,10 @@ M.formatters = {
end,
file_icon = function(ctx)
local item = ctx.item --[[@as Diagnostic|trouble.Item]]
local ok, icons = pcall(require, "nvim-web-devicons")
if not ok then
return ""
end
local fname = vim.fn.fnamemodify(item.filename, ":t")
local file = vim.fn.fnamemodify(item.filename, ":t")
local ext = vim.fn.fnamemodify(item.filename, ":e")
local icon, color = icons.get_icon(fname, ext, { default = true })
return { text = icon .. " ", hl = color }
local icon, color = M.get_icon(file, ext)
return icon and { text = icon .. " ", hl = color } or ""
end,
count = function(ctx)
return {
Expand Down

0 comments on commit 42dcb58

Please sign in to comment.