feat (sidebar) nvim-web-devicons support files with multiple dots and use default for unknown file types. (#943)

This commit is contained in:
Christopher Brewin
2024-12-14 00:54:16 +10:00
committed by GitHub
parent 78dd9b0a6d
commit 4d6f8e65fb
2 changed files with 25 additions and 20 deletions

View File

@@ -1,4 +1,5 @@
local LRUCache = require("avante.utils.lru_cache")
local Filetype = require("plenary.filetype")
---@class avante.utils.file
local M = {}
@@ -38,4 +39,27 @@ function M.exists(filepath)
return stat ~= nil
end
function M.get_file_icon(filepath)
local filetype = Filetype.detect(filepath, {}) or "unknown"
---@type string
local icon
---@diagnostic disable-next-line: undefined-field
if _G.MiniIcons ~= nil then
---@diagnostic disable-next-line: undefined-global
icon, _, _ = MiniIcons.get("filetype", filetype) -- luacheck: ignore
else
local ok, devicons = pcall(require, "nvim-web-devicons")
if ok then
icon = devicons.get_icon(filepath, filetype, { default = false })
if not icon then
icon = devicons.get_icon(filepath, nil, { default = true })
icon = icon or " "
end
else
icon = ""
end
end
return icon
end
return M