mirror of
https://github.com/stevearc/aerial.nvim
synced 2024-09-08 02:35:44 +02:00
feat: add support for mini.icons
(#383)
This commit is contained in:
parent
7e2615991c
commit
3d910b2ba0
4 changed files with 42 additions and 13 deletions
|
@ -342,7 +342,7 @@ require("aerial").setup({
|
|||
-- icon when the tree is collapsed at that symbol, or "Collapsed" to specify a
|
||||
-- default collapsed icon. The default icon set is determined by the
|
||||
-- "nerd_font" option below.
|
||||
-- If you have lspkind-nvim installed, it will be the default icon set.
|
||||
-- If you have mini.icons or lspkind-nvim installed, it will be the default icon set.
|
||||
-- This can be a filetype map (see :help aerial-filetype-map)
|
||||
icons = {},
|
||||
|
||||
|
@ -395,7 +395,7 @@ require("aerial").setup({
|
|||
link_tree_to_folds = true,
|
||||
|
||||
-- Set default symbol icons to use patched font icons (see https://www.nerdfonts.com/)
|
||||
-- "auto" will set it to true if nvim-web-devicons or lspkind-nvim is installed.
|
||||
-- "auto" will set it to true if nvim-web-devicons, lspkind-nvim, or mini.icons is installed.
|
||||
nerd_font = "auto",
|
||||
|
||||
-- Call this function when aerial attaches to a buffer.
|
||||
|
|
|
@ -150,7 +150,7 @@ OPTIONS *aerial-option
|
|||
-- icon when the tree is collapsed at that symbol, or "Collapsed" to specify a
|
||||
-- default collapsed icon. The default icon set is determined by the
|
||||
-- "nerd_font" option below.
|
||||
-- If you have lspkind-nvim installed, it will be the default icon set.
|
||||
-- If you have mini.icons or lspkind-nvim installed, it will be the default icon set.
|
||||
-- This can be a filetype map (see :help aerial-filetype-map)
|
||||
icons = {},
|
||||
|
||||
|
@ -203,7 +203,7 @@ OPTIONS *aerial-option
|
|||
link_tree_to_folds = true,
|
||||
|
||||
-- Set default symbol icons to use patched font icons (see https://www.nerdfonts.com/)
|
||||
-- "auto" will set it to true if nvim-web-devicons or lspkind-nvim is installed.
|
||||
-- "auto" will set it to true if nvim-web-devicons, lspkind-nvim, or mini.icons is installed.
|
||||
nerd_font = "auto",
|
||||
|
||||
-- Call this function when aerial attaches to a buffer.
|
||||
|
|
|
@ -504,7 +504,9 @@ M.setup = function(opts)
|
|||
if newconf.nerd_font == "auto" then
|
||||
local has_devicons = pcall(require, "nvim-web-devicons")
|
||||
local has_lspkind = pcall(require, "lspkind")
|
||||
newconf.nerd_font = has_devicons or has_lspkind
|
||||
pcall(require, "mini.icons")
|
||||
local has_miniicons = vim.tbl_get(_G, "MiniIcons", "config", "style") == "glyph"
|
||||
newconf.nerd_font = has_devicons or has_lspkind or has_miniicons
|
||||
end
|
||||
|
||||
-- Add lookup to close_automatic_events
|
||||
|
@ -512,10 +514,10 @@ M.setup = function(opts)
|
|||
newconf.close_automatic_events[v] = i
|
||||
end
|
||||
|
||||
-- Undocumented use_lspkind option for tests. End users can simply provide
|
||||
-- Undocumented use_icon_provider option for tests. End users can simply provide
|
||||
-- their own icons
|
||||
if newconf.use_lspkind == nil then
|
||||
newconf.use_lspkind = true
|
||||
if newconf.use_icon_provider == nil then
|
||||
newconf.use_icon_provider = true
|
||||
end
|
||||
|
||||
newconf.default_icons = newconf.nerd_font and nerd_icons or plain_icons
|
||||
|
@ -580,6 +582,31 @@ local function get_icon(kind, filetypes)
|
|||
return M.icons[kind]
|
||||
end
|
||||
|
||||
local function get_icon_provider()
|
||||
if not M.use_icon_provider then -- skip if icon provider not used
|
||||
return false
|
||||
end
|
||||
-- prefer mini.icons
|
||||
local _, mini_icons = pcall(require, "mini.icons")
|
||||
---@diagnostic disable-next-line: undefined-field
|
||||
if _G.MiniIcons then -- `_G.MiniIcons` is a better check to see if the module is setup
|
||||
return function(kind)
|
||||
return mini_icons.get("lsp", kind)
|
||||
end
|
||||
end
|
||||
|
||||
-- fallback to `lspkind`
|
||||
local has_lspkind, lspkind = pcall(require, "lspkind")
|
||||
if has_lspkind then
|
||||
return function(kind)
|
||||
return lspkind.symbolic(kind, { mode = "symbolic " })
|
||||
end
|
||||
end
|
||||
|
||||
return false -- no icon provider
|
||||
end
|
||||
|
||||
local icon_provider
|
||||
M.get_icon = function(bufnr, kind, collapsed)
|
||||
if collapsed then
|
||||
kind = kind .. "Collapsed"
|
||||
|
@ -598,9 +625,11 @@ M.get_icon = function(bufnr, kind, collapsed)
|
|||
end
|
||||
end
|
||||
|
||||
local has_lspkind, lspkind = pcall(require, "lspkind")
|
||||
if has_lspkind and M.use_lspkind and not collapsed then
|
||||
icon = lspkind.symbolic(kind, { with_text = false })
|
||||
if icon_provider == nil then
|
||||
icon_provider = get_icon_provider()
|
||||
end
|
||||
if icon_provider and not collapsed then
|
||||
icon = icon_provider(kind)
|
||||
if icon and icon ~= "" then
|
||||
return icon
|
||||
end
|
||||
|
|
|
@ -86,7 +86,7 @@ describe("config", function()
|
|||
|
||||
-- Icons
|
||||
it("reads icons from the default table", function()
|
||||
config.setup({ nerd_font = true, use_lspkind = false })
|
||||
config.setup({ nerd_font = true, use_icon_provider = false })
|
||||
assert.equals(" ", config.get_icon(0, "Function", false))
|
||||
end)
|
||||
it("reads icons from setup var", function()
|
||||
|
@ -95,7 +95,7 @@ describe("config", function()
|
|||
icons = {
|
||||
Function = "*",
|
||||
},
|
||||
use_lspkind = false,
|
||||
use_icon_provider = false,
|
||||
})
|
||||
assert.equals("*", config.get_icon(0, "Function", false))
|
||||
assert.equals(" ", config.get_icon(0, "Method", false))
|
||||
|
|
Loading…
Reference in a new issue