1+ local config = require (" nvim-tree.config" )
2+
13--- @alias devicons_get_icon fun ( name : string , ext : string ?, opts : table ?): string ?, string ?
24--- @alias devicons_setup fun ( opts : table ?)
35
68--- @field get_icon devicons_get_icon
79local devicons
810
9- local M = {}
11+ -- One shot lazy discovery and setup done
12+ local initialized = false
1013
11- --- Wrapper around nvim-web-devicons, nils if devicons not available
12- --- @type devicons_get_icon
13- function M .get_icon (name , ext , opts )
14- if devicons then
15- return devicons .get_icon (name , ext , opts )
16- else
17- return nil , nil
18- end
19- end
14+ local M = {}
2015
2116--- Attempt to use nvim-web-devicons if present and enabled for file or folder
22- --- @param opts table
23- function M .setup (opts )
24- if opts .renderer .icons .show .file or opts .renderer .icons .show .folder then
17+ local function initialize ()
18+ if config .g .renderer .icons .show .file or config .g .renderer .icons .show .folder then
2519 local ok , di = pcall (require , " nvim-web-devicons" )
2620 if ok then
2721 devicons = di --[[ @as DevIcons]]
@@ -30,6 +24,21 @@ function M.setup(opts)
3024 devicons .setup ()
3125 end
3226 end
27+ initialized = true
28+ end
29+
30+ --- Wrapper around nvim-web-devicons, nils if devicons not available
31+ --- @type devicons_get_icon
32+ function M .get_icon (name , ext , opts )
33+ if not initialized then
34+ initialize ()
35+ end
36+
37+ if devicons then
38+ return devicons .get_icon (name , ext , opts )
39+ else
40+ return nil , nil
41+ end
3342end
3443
3544return M
0 commit comments