feat (sidebar) nvim-web-devicons support files with multiple dots and use default for unknown file types. (#943)
This commit is contained in:
parent
78dd9b0a6d
commit
4d6f8e65fb
@ -755,25 +755,6 @@ function Sidebar:render_result()
|
||||
)
|
||||
end
|
||||
|
||||
function Sidebar:get_file_icon(filepath)
|
||||
local filetype = vim.filetype.match({ filename = 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_by_filetype(filetype, {})
|
||||
else
|
||||
icon = ""
|
||||
end
|
||||
end
|
||||
return icon
|
||||
end
|
||||
|
||||
---@param ask? boolean
|
||||
function Sidebar:render_input(ask)
|
||||
if ask == nil then ask = true end
|
||||
@ -2050,7 +2031,7 @@ function Sidebar:create_selected_files_container()
|
||||
|
||||
local selected_filepaths_with_icon = {}
|
||||
for _, filepath in ipairs(selected_filepaths_) do
|
||||
local icon = self:get_file_icon(filepath)
|
||||
local icon = Utils.file.get_file_icon(filepath)
|
||||
table.insert(selected_filepaths_with_icon, string.format("%s %s", icon, filepath))
|
||||
end
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user