fix(util): better support for nvim-web-devicons

This commit is contained in:
Folke Lemaitre 2024-12-01 17:57:28 +01:00
parent ca7188c531
commit ddaa2aaba5
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -56,10 +56,21 @@ end
---@param cat? string
---@return string, string?
function M.icon(name, cat)
-- stylua: ignore
local try = {
function() return require("mini.icons").get(cat or "file", name) end,
function() return require("nvim-web-devicons").get_icon(name) end,
function()
return require("mini.icons").get(cat or "file", name)
end,
function()
local Icons = require("nvim-web-devicons")
if cat == "filetype" then
return Icons.get_icon_by_filetype(name, { default = false })
elseif cat == "file" then
local ext = name:match("%.(%w+)$")
return Icons.get_icon(name, ext, { default = false }) --[[@as string, string]]
elseif cat == "extension" then
return Icons.get_icon(nil, name, { default = false }) --[[@as string, string]]
end
end,
}
for _, fn in ipairs(try) do
local ret = { pcall(fn) }