Skip to content

Commit 3603f06

Browse files
authored
perf(#3257): remove setup for renderer, log, appearance (#3307)
* perf(#3257): remove devicons setup * perf(#3257): remove padding setup * perf(#3257): remove appearance and log setup * perf(#3257): remove appearance setup * perf(#3257): remove rename-file setup * perf(#3257): remove devicons setup * perf(#3257): remove appearance setup * perf(#3257): inline require legacy notify * perf(#3257): inline require events notify * perf(#3257): inline require log notify
1 parent 4cbe795 commit 3603f06

File tree

11 files changed

+73
-74
lines changed

11 files changed

+73
-74
lines changed

lua/nvim-tree.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,15 +281,14 @@ function M.setup(config_user)
281281

282282
manage_netrw()
283283

284-
require("nvim-tree.log").setup(config.g)
284+
log.start()
285285

286286
if log.enabled("config") then
287287
log.line("config", "default config + user")
288288
log.raw("config", "%s\n", vim.inspect(config.g))
289289
end
290290

291-
require("nvim-tree.appearance").setup()
292-
require("nvim-tree.renderer.components").setup(config.g)
291+
require("nvim-tree.appearance").highlight()
293292

294293
require("nvim-tree.view-state").initialize()
295294

lua/nvim-tree/actions/fs/rename-file.lua

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,4 @@ function M.rename_full(node)
192192
prompt_to_rename(node, ":p")
193193
end
194194

195-
function M.setup(opts)
196-
config.g.filesystem_watchers = opts.filesystem_watchers
197-
end
198-
199195
return M

lua/nvim-tree/appearance/init.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ M.LEGACY_LINKS = {
182182
NvimTreeDiagnosticHintFolderHL = "NvimTreeLspDiagnosticsHintFolderText",
183183
}
184184

185-
function M.setup()
185+
---Create all highlight groups and links. Idempotent.
186+
function M.highlight()
186187
-- non-linked
187188
for _, g in ipairs(M.HIGHLIGHT_GROUPS) do
188189
if g.def then

lua/nvim-tree/config.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,21 @@ local function process_config(g)
511511
-- Open
512512
--
513513
g.actions.open_file.window_picker.chars = tostring(g.actions.open_file.window_picker.chars):upper()
514+
515+
--
516+
-- Padding
517+
--
518+
if g.renderer.indent_width < 1 then
519+
g.renderer.indent_width = 1
520+
end
521+
for k, v in pairs(g.renderer.indent_markers.icons) do
522+
if #v == 0 then
523+
g.renderer.indent_markers.icons[k] = " "
524+
else
525+
-- return the first character from the UTF-8 encoded string; we may use utf8.codes from Lua 5.3 when available
526+
g.renderer.indent_markers.icons[k] = v:match("[%z\1-\127\194-\244][\128-\191]*")
527+
end
528+
end
514529
end
515530

516531
---Validate user config and migrate legacy.

lua/nvim-tree/events.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
local notify = require("nvim-tree.notify")
21
local Event = require("nvim-tree._meta.api.events").Event
32

43
local M = {}
@@ -25,7 +24,7 @@ local function dispatch(event_name, payload)
2524
for _, handler in pairs(get_handlers(event_name)) do
2625
local success, error = pcall(handler, payload)
2726
if not success then
28-
notify.error("Handler for event " .. event_name .. " errored. " .. vim.inspect(error))
27+
require("nvim-tree.notify").error("Handler for event " .. event_name .. " errored. " .. vim.inspect(error))
2928
end
3029
end
3130
end

lua/nvim-tree/explorer/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function Explorer:create_autocmds()
8888
vim.api.nvim_create_autocmd("ColorScheme", {
8989
group = self.augroup_id,
9090
callback = function()
91-
appearance.setup()
91+
appearance.highlight()
9292
view.reset_winhl()
9393
self.renderer:draw()
9494
end,

lua/nvim-tree/legacy.lua

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
local notify = require("nvim-tree.notify")
2-
31
local M = {}
42

53
--- Create empty sub-tables if not present
@@ -120,25 +118,32 @@ end
120118
---@param u nvim_tree.config user supplied subset of config
121119
local function deprecated_config(u)
122120
if type(u.view) == "table" and u.view.hide_root_folder then
123-
notify.info("view.hide_root_folder is deprecated, please set renderer.root_folder_label = false")
121+
require("nvim-tree.notify").info(
122+
"view.hide_root_folder is deprecated, please set renderer.root_folder_label = false"
123+
)
124124
end
125125
end
126126

127127
---@param u nvim_tree.config user supplied subset of config
128128
local function removed_config(u)
129129
if u.auto_close then
130-
notify.warn("auto close feature has been removed: https://github.com/nvim-tree/nvim-tree.lua/wiki/Auto-Close")
130+
require("nvim-tree.notify").warn(
131+
"auto close feature has been removed: https://github.com/nvim-tree/nvim-tree.lua/wiki/Auto-Close"
132+
)
131133
u["auto_close"] = nil
132134
end
133135

134136
if u.focus_empty_on_setup then
135-
notify.warn("focus_empty_on_setup has been removed: https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup")
137+
require("nvim-tree.notify").warn(
138+
"focus_empty_on_setup has been removed: https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup"
139+
)
136140
u["focus_empty_on_setup"] = nil
137141
end
138142

139143
if u.create_in_closed_folder then
140-
notify.warn(
141-
"create_in_closed_folder has been removed and is now the default behaviour. You may use api.fs.create to add a file under your desired node.")
144+
require("nvim-tree.notify").warn(
145+
"create_in_closed_folder has been removed and is now the default behaviour. You may use api.fs.create to add a file under your desired node."
146+
)
142147
end
143148
u["create_in_closed_folder"] = nil
144149
end

lua/nvim-tree/log.lua

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local config = require("nvim-tree.config")
2+
13
---@alias LogTypes "all" | "config" | "copy_paste" | "dev" | "diagnostics" | "git" | "profile" | "watcher"
24

35
---@type table<LogTypes, boolean>
@@ -110,14 +112,17 @@ function M.enabled(typ)
110112
return file_path ~= nil and (types[typ] or types.all)
111113
end
112114

113-
function M.setup(opts)
114-
if opts.log and opts.log.enable and opts.log.types then
115-
types = opts.log.types
115+
--- Create the log file and enable logging, if globally configured
116+
function M.start()
117+
if config.g.log and config.g.log.enable and config.g.log.types then
118+
types = config.g.log.types
116119
file_path = string.format("%s/nvim-tree.log", vim.fn.stdpath("log"), os.date("%H:%M:%S"), vim.env.USER)
117-
if opts.log.truncate then
120+
if config.g.log.truncate then
118121
os.remove(file_path)
119122
end
120-
require("nvim-tree.notify").debug("nvim-tree.lua logging to " .. file_path)
123+
if config.g.notify.threshold <= vim.log.levels.DEBUG then
124+
require("nvim-tree.notify").debug("nvim-tree.lua logging to " .. file_path)
125+
end
121126
end
122127
end
123128

Lines changed: 12 additions & 3 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,11 +8,18 @@
68
---@field get_icon devicons_get_icon
79
local devicons
810

11+
--One shot lazy discovery and setup done
12+
local initialized = false
13+
914
local M = {}
1015

1116
---Wrapper around nvim-web-devicons, nils if devicons not available
1217
---@type devicons_get_icon
1318
function M.get_icon(name, ext, opts)
19+
if not initialized then
20+
M.initialize()
21+
end
22+
1423
if devicons then
1524
return devicons.get_icon(name, ext, opts)
1625
else
@@ -19,9 +28,8 @@ function M.get_icon(name, ext, opts)
1928
end
2029

2130
---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
31+
function M.initialize()
32+
if config.g.renderer.icons.show.file or config.g.renderer.icons.show.folder then
2533
local ok, di = pcall(require, "nvim-web-devicons")
2634
if ok then
2735
devicons = di --[[@as DevIcons]]
@@ -30,6 +38,7 @@ function M.setup(opts)
3038
devicons.setup()
3139
end
3240
end
41+
initialized = true
3342
end
3443

3544
return M

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

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)