Skip to content

Commit 5feffb7

Browse files
committed
perf(#3257): remove devicons setup
1 parent c45a951 commit 5feffb7

2 files changed

Lines changed: 22 additions & 15 deletions

File tree

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
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

@@ -6,22 +8,14 @@
68
---@field get_icon devicons_get_icon
79
local 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
3342
end
3443

3544
return M

lua/nvim-tree/renderer/components/init.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
local M = {}
22

3-
M.devicons = require("nvim-tree.renderer.components.devicons")
43
M.padding = require("nvim-tree.renderer.components.padding")
54

65
function M.setup(opts)
7-
M.devicons.setup(opts)
86
M.padding.setup(opts)
97
end
108

0 commit comments

Comments
 (0)