From f495542e5e71186c03a5ff879475c3522bd6bff2 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 28 Mar 2026 12:14:50 +1100 Subject: [PATCH 01/10] perf(#3257): remove devicons setup --- .../renderer/components/devicons.lua | 35 ++++++++++++------- lua/nvim-tree/renderer/components/init.lua | 2 -- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/lua/nvim-tree/renderer/components/devicons.lua b/lua/nvim-tree/renderer/components/devicons.lua index ad91d058c15..d5fd307c2cd 100644 --- a/lua/nvim-tree/renderer/components/devicons.lua +++ b/lua/nvim-tree/renderer/components/devicons.lua @@ -1,3 +1,5 @@ +local config = require("nvim-tree.config") + ---@alias devicons_get_icon fun(name: string, ext: string?, opts: table?): string?, string? ---@alias devicons_setup fun(opts: table?) @@ -6,22 +8,14 @@ ---@field get_icon devicons_get_icon local devicons -local M = {} +--One shot lazy discovery and setup done +local initialized = false ----Wrapper around nvim-web-devicons, nils if devicons not available ----@type devicons_get_icon -function M.get_icon(name, ext, opts) - if devicons then - return devicons.get_icon(name, ext, opts) - else - return nil, nil - end -end +local M = {} ---Attempt to use nvim-web-devicons if present and enabled for file or folder ----@param opts table -function M.setup(opts) - if opts.renderer.icons.show.file or opts.renderer.icons.show.folder then +local function initialize() + if config.g.renderer.icons.show.file or config.g.renderer.icons.show.folder then local ok, di = pcall(require, "nvim-web-devicons") if ok then devicons = di --[[@as DevIcons]] @@ -30,6 +24,21 @@ function M.setup(opts) devicons.setup() end end + initialized = true +end + +---Wrapper around nvim-web-devicons, nils if devicons not available +---@type devicons_get_icon +function M.get_icon(name, ext, opts) + if not initialized then + initialize() + end + + if devicons then + return devicons.get_icon(name, ext, opts) + else + return nil, nil + end end return M diff --git a/lua/nvim-tree/renderer/components/init.lua b/lua/nvim-tree/renderer/components/init.lua index a06827422dd..5ef3bbd6d8e 100644 --- a/lua/nvim-tree/renderer/components/init.lua +++ b/lua/nvim-tree/renderer/components/init.lua @@ -1,10 +1,8 @@ local M = {} -M.devicons = require("nvim-tree.renderer.components.devicons") M.padding = require("nvim-tree.renderer.components.padding") function M.setup(opts) - M.devicons.setup(opts) M.padding.setup(opts) end From 0042f7d33c3fe466e5ac3036209c84a45abcc468 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 28 Mar 2026 12:49:51 +1100 Subject: [PATCH 02/10] perf(#3257): remove padding setup --- lua/nvim-tree.lua | 1 - lua/nvim-tree/config.lua | 15 +++++ lua/nvim-tree/renderer/components/init.lua | 9 --- lua/nvim-tree/renderer/components/padding.lua | 55 ++++++------------- 4 files changed, 33 insertions(+), 47 deletions(-) delete mode 100644 lua/nvim-tree/renderer/components/init.lua diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 63cf5d1c154..a4ab3f2cd92 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -289,7 +289,6 @@ function M.setup(config_user) end require("nvim-tree.appearance").setup() - require("nvim-tree.renderer.components").setup(config.g) require("nvim-tree.view-state").initialize() diff --git a/lua/nvim-tree/config.lua b/lua/nvim-tree/config.lua index 8e819961a6d..5c3403d36d7 100644 --- a/lua/nvim-tree/config.lua +++ b/lua/nvim-tree/config.lua @@ -511,6 +511,21 @@ local function process_config(g) -- Open -- g.actions.open_file.window_picker.chars = tostring(g.actions.open_file.window_picker.chars):upper() + + -- + -- Padding + -- + if g.renderer.indent_width < 1 then + g.renderer.indent_width = 1 + end + for k, v in pairs(g.renderer.indent_markers.icons) do + if #v == 0 then + g.renderer.indent_markers.icons[k] = " " + else + -- return the first character from the UTF-8 encoded string; we may use utf8.codes from Lua 5.3 when available + g.renderer.indent_markers.icons[k] = v:match("[%z\1-\127\194-\244][\128-\191]*") + end + end end ---Validate user config and migrate legacy. diff --git a/lua/nvim-tree/renderer/components/init.lua b/lua/nvim-tree/renderer/components/init.lua deleted file mode 100644 index 5ef3bbd6d8e..00000000000 --- a/lua/nvim-tree/renderer/components/init.lua +++ /dev/null @@ -1,9 +0,0 @@ -local M = {} - -M.padding = require("nvim-tree.renderer.components.padding") - -function M.setup(opts) - M.padding.setup(opts) -end - -return M diff --git a/lua/nvim-tree/renderer/components/padding.lua b/lua/nvim-tree/renderer/components/padding.lua index be84ae0b9de..9e04addfdaf 100644 --- a/lua/nvim-tree/renderer/components/padding.lua +++ b/lua/nvim-tree/renderer/components/padding.lua @@ -1,3 +1,4 @@ +local config = require("nvim-tree.config") local DirectoryNode = require("nvim-tree.node.directory") local M = {} @@ -27,21 +28,21 @@ local function get_padding_indent_markers(depth, idx, nodes_number, markers, wit if depth > 0 then local has_folder_sibling = check_siblings_for_folder(node, with_arrows) - local indent = string.rep(" ", M.config.indent_width - 1) + local indent = string.rep(" ", config.g.renderer.indent_width - 1) markers[depth] = idx ~= nodes_number for i = 1, depth - early_stop do local glyph if idx == nodes_number and i == depth then - local bottom_width = M.config.indent_width - 2 + (with_arrows and not inline_arrows and has_folder_sibling and 2 or 0) - glyph = M.config.indent_markers.icons.corner - .. string.rep(M.config.indent_markers.icons.bottom, bottom_width) - .. (M.config.indent_width > 1 and " " or "") + local bottom_width = config.g.renderer.indent_width - 2 + (with_arrows and not inline_arrows and has_folder_sibling and 2 or 0) + glyph = config.g.renderer.indent_markers.icons.corner + .. string.rep(config.g.renderer.indent_markers.icons.bottom, bottom_width) + .. (config.g.renderer.indent_width > 1 and " " or "") elseif markers[i] and i == depth then - glyph = M.config.indent_markers.icons.item .. indent + glyph = config.g.renderer.indent_markers.icons.item .. indent elseif markers[i] then - glyph = M.config.indent_markers.icons.edge .. indent + glyph = config.g.renderer.indent_markers.icons.edge .. indent else - glyph = M.config.indent_markers.icons.none .. indent + glyph = config.g.renderer.indent_markers.icons.none .. indent end if not with_arrows or (inline_arrows and (depth ~= i or not node.nodes)) then @@ -68,10 +69,10 @@ end function M.get_indent_markers(depth, idx, nodes_number, node, markers, early_stop) local str = "" - local show_arrows = M.config.icons.show.folder_arrow - local show_markers = M.config.indent_markers.enable - local inline_arrows = M.config.indent_markers.inline_arrows - local indent_width = M.config.indent_width + local show_arrows = config.g.renderer.icons.show.folder_arrow + local show_markers = config.g.renderer.indent_markers.enable + local inline_arrows = config.g.renderer.indent_markers.inline_arrows + local indent_width = config.g.renderer.indent_width if show_markers then str = str .. get_padding_indent_markers(depth, idx, nodes_number, markers, show_arrows, inline_arrows, node, early_stop or 0) @@ -85,7 +86,7 @@ end ---@param node Node ---@return nvim_tree.api.highlighted_string[]? function M.get_arrows(node) - if not M.config.icons.show.folder_arrow then + if not config.g.renderer.icons.show.folder_arrow then return end @@ -95,38 +96,18 @@ function M.get_arrows(node) local dir = node:as(DirectoryNode) if dir then if dir.open then - str = M.config.icons.glyphs.folder["arrow_open"] .. M.config.icons.padding.folder_arrow + str = config.g.renderer.icons.glyphs.folder["arrow_open"] .. config.g.renderer.icons.padding.folder_arrow hl = "NvimTreeFolderArrowOpen" else - str = M.config.icons.glyphs.folder["arrow_closed"] .. M.config.icons.padding.folder_arrow + str = config.g.renderer.icons.glyphs.folder["arrow_closed"] .. config.g.renderer.icons.padding.folder_arrow end - elseif M.config.indent_markers.enable then + elseif config.g.renderer.indent_markers.enable then str = "" else - str = " " .. string.rep(" ", #M.config.icons.padding.folder_arrow) + str = " " .. string.rep(" ", #config.g.renderer.icons.padding.folder_arrow) end return { str = str, hl = { hl } } end -function M.setup(opts) - M.config = opts.renderer - - if M.config.indent_width < 1 then - M.config.indent_width = 1 - end - - local function check_marker(symbol) - if #symbol == 0 then - return " " - end - -- return the first character from the UTF-8 encoded string; we may use utf8.codes from Lua 5.3 when available - return symbol:match("[%z\1-\127\194-\244][\128-\191]*") - end - - for k, v in pairs(M.config.indent_markers.icons) do - M.config.indent_markers.icons[k] = check_marker(v) - end -end - return M From f917e9d50912cc251f2547df3c9d301e8686ba58 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 28 Mar 2026 13:24:43 +1100 Subject: [PATCH 03/10] perf(#3257): remove appearance and log setup --- lua/nvim-tree.lua | 4 ++-- lua/nvim-tree/appearance/init.lua | 3 ++- lua/nvim-tree/explorer/init.lua | 2 +- lua/nvim-tree/log.lua | 11 +++++++---- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index a4ab3f2cd92..0bf4fe91f30 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -281,14 +281,14 @@ function M.setup(config_user) manage_netrw() - require("nvim-tree.log").setup(config.g) + require("nvim-tree.log").start() if log.enabled("config") then log.line("config", "default config + user") log.raw("config", "%s\n", vim.inspect(config.g)) end - require("nvim-tree.appearance").setup() + require("nvim-tree.appearance").define_hi() require("nvim-tree.view-state").initialize() diff --git a/lua/nvim-tree/appearance/init.lua b/lua/nvim-tree/appearance/init.lua index 61714af644e..1b8d27cedc1 100644 --- a/lua/nvim-tree/appearance/init.lua +++ b/lua/nvim-tree/appearance/init.lua @@ -182,7 +182,8 @@ M.LEGACY_LINKS = { NvimTreeDiagnosticHintFolderHL = "NvimTreeLspDiagnosticsHintFolderText", } -function M.setup() +---Create all highlight groups and links. Idempotent. +function M.define_hi() -- non-linked for _, g in ipairs(M.HIGHLIGHT_GROUPS) do if g.def then diff --git a/lua/nvim-tree/explorer/init.lua b/lua/nvim-tree/explorer/init.lua index eb9b5f5d097..3559a74cf5c 100644 --- a/lua/nvim-tree/explorer/init.lua +++ b/lua/nvim-tree/explorer/init.lua @@ -88,7 +88,7 @@ function Explorer:create_autocmds() vim.api.nvim_create_autocmd("ColorScheme", { group = self.augroup_id, callback = function() - appearance.setup() + appearance.define_hi() view.reset_winhl() self.renderer:draw() end, diff --git a/lua/nvim-tree/log.lua b/lua/nvim-tree/log.lua index 9665c1335e6..ff5686061fd 100644 --- a/lua/nvim-tree/log.lua +++ b/lua/nvim-tree/log.lua @@ -1,3 +1,5 @@ +local config = require("nvim-tree.config") + ---@alias LogTypes "all" | "config" | "copy_paste" | "dev" | "diagnostics" | "git" | "profile" | "watcher" ---@type table @@ -110,11 +112,12 @@ function M.enabled(typ) return file_path ~= nil and (types[typ] or types.all) end -function M.setup(opts) - if opts.log and opts.log.enable and opts.log.types then - types = opts.log.types +--- Create the log file and enable logging, if globally configured +function M.start() + if config.g.log and config.g.log.enable and config.g.log.types then + types = config.g.log.types file_path = string.format("%s/nvim-tree.log", vim.fn.stdpath("log"), os.date("%H:%M:%S"), vim.env.USER) - if opts.log.truncate then + if config.g.log.truncate then os.remove(file_path) end require("nvim-tree.notify").debug("nvim-tree.lua logging to " .. file_path) From 2036eecc4b8e553843c71e343bf05a0b839b6473 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 28 Mar 2026 13:28:52 +1100 Subject: [PATCH 04/10] perf(#3257): remove appearance setup --- lua/nvim-tree.lua | 2 +- lua/nvim-tree/appearance/init.lua | 2 +- lua/nvim-tree/explorer/init.lua | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 0bf4fe91f30..2fb77ed0a16 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -288,7 +288,7 @@ function M.setup(config_user) log.raw("config", "%s\n", vim.inspect(config.g)) end - require("nvim-tree.appearance").define_hi() + require("nvim-tree.appearance").set_hl() require("nvim-tree.view-state").initialize() diff --git a/lua/nvim-tree/appearance/init.lua b/lua/nvim-tree/appearance/init.lua index 1b8d27cedc1..9190ad07d49 100644 --- a/lua/nvim-tree/appearance/init.lua +++ b/lua/nvim-tree/appearance/init.lua @@ -183,7 +183,7 @@ M.LEGACY_LINKS = { } ---Create all highlight groups and links. Idempotent. -function M.define_hi() +function M.set_hl() -- non-linked for _, g in ipairs(M.HIGHLIGHT_GROUPS) do if g.def then diff --git a/lua/nvim-tree/explorer/init.lua b/lua/nvim-tree/explorer/init.lua index 3559a74cf5c..d33be5f10bf 100644 --- a/lua/nvim-tree/explorer/init.lua +++ b/lua/nvim-tree/explorer/init.lua @@ -88,7 +88,7 @@ function Explorer:create_autocmds() vim.api.nvim_create_autocmd("ColorScheme", { group = self.augroup_id, callback = function() - appearance.define_hi() + appearance.set_hl() view.reset_winhl() self.renderer:draw() end, From 68182509696d6847ab73c9e6ed2f277603e9f962 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 28 Mar 2026 13:31:14 +1100 Subject: [PATCH 05/10] perf(#3257): remove rename-file setup --- lua/nvim-tree/actions/fs/rename-file.lua | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lua/nvim-tree/actions/fs/rename-file.lua b/lua/nvim-tree/actions/fs/rename-file.lua index 0b4f22ac1d7..0740b813841 100644 --- a/lua/nvim-tree/actions/fs/rename-file.lua +++ b/lua/nvim-tree/actions/fs/rename-file.lua @@ -192,8 +192,4 @@ function M.rename_full(node) prompt_to_rename(node, ":p") end -function M.setup(opts) - config.g.filesystem_watchers = opts.filesystem_watchers -end - return M From 77ed15f0457b4ab3bec6897d6575b5bfcb1332fb Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Mon, 30 Mar 2026 14:32:49 +1100 Subject: [PATCH 06/10] perf(#3257): remove devicons setup --- .../renderer/components/devicons.lua | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lua/nvim-tree/renderer/components/devicons.lua b/lua/nvim-tree/renderer/components/devicons.lua index d5fd307c2cd..5d7bd275161 100644 --- a/lua/nvim-tree/renderer/components/devicons.lua +++ b/lua/nvim-tree/renderer/components/devicons.lua @@ -13,25 +13,11 @@ local initialized = false local M = {} ----Attempt to use nvim-web-devicons if present and enabled for file or folder -local function initialize() - if config.g.renderer.icons.show.file or config.g.renderer.icons.show.folder then - local ok, di = pcall(require, "nvim-web-devicons") - if ok then - devicons = di --[[@as DevIcons]] - - -- does nothing if already called i.e. doesn't clobber previous user setup - devicons.setup() - end - end - initialized = true -end - ---Wrapper around nvim-web-devicons, nils if devicons not available ---@type devicons_get_icon function M.get_icon(name, ext, opts) if not initialized then - initialize() + M.initialize() end if devicons then @@ -41,4 +27,18 @@ function M.get_icon(name, ext, opts) end end +---Attempt to use nvim-web-devicons if present and enabled for file or folder +function M.initialize() + if config.g.renderer.icons.show.file or config.g.renderer.icons.show.folder then + local ok, di = pcall(require, "nvim-web-devicons") + if ok then + devicons = di --[[@as DevIcons]] + + -- does nothing if already called i.e. doesn't clobber previous user setup + devicons.setup() + end + end + initialized = true +end + return M From 50e7e4c78e73df887b9431c23178ad31c4c97fed Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Mon, 30 Mar 2026 14:50:52 +1100 Subject: [PATCH 07/10] perf(#3257): remove appearance setup --- lua/nvim-tree.lua | 2 +- lua/nvim-tree/appearance/init.lua | 2 +- lua/nvim-tree/explorer/init.lua | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 2fb77ed0a16..509a99bd1cb 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -288,7 +288,7 @@ function M.setup(config_user) log.raw("config", "%s\n", vim.inspect(config.g)) end - require("nvim-tree.appearance").set_hl() + require("nvim-tree.appearance").highlight() require("nvim-tree.view-state").initialize() diff --git a/lua/nvim-tree/appearance/init.lua b/lua/nvim-tree/appearance/init.lua index 9190ad07d49..9918ca4dd0b 100644 --- a/lua/nvim-tree/appearance/init.lua +++ b/lua/nvim-tree/appearance/init.lua @@ -183,7 +183,7 @@ M.LEGACY_LINKS = { } ---Create all highlight groups and links. Idempotent. -function M.set_hl() +function M.highlight() -- non-linked for _, g in ipairs(M.HIGHLIGHT_GROUPS) do if g.def then diff --git a/lua/nvim-tree/explorer/init.lua b/lua/nvim-tree/explorer/init.lua index d33be5f10bf..84af434edba 100644 --- a/lua/nvim-tree/explorer/init.lua +++ b/lua/nvim-tree/explorer/init.lua @@ -88,7 +88,7 @@ function Explorer:create_autocmds() vim.api.nvim_create_autocmd("ColorScheme", { group = self.augroup_id, callback = function() - appearance.set_hl() + appearance.highlight() view.reset_winhl() self.renderer:draw() end, From b7b1b980eeb6608022a6cc72f85741cbbc89304b Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Mon, 30 Mar 2026 14:59:01 +1100 Subject: [PATCH 08/10] perf(#3257): inline require legacy notify --- lua/nvim-tree/legacy.lua | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lua/nvim-tree/legacy.lua b/lua/nvim-tree/legacy.lua index 7d42338abd5..ed432c51ed3 100644 --- a/lua/nvim-tree/legacy.lua +++ b/lua/nvim-tree/legacy.lua @@ -1,5 +1,3 @@ -local notify = require("nvim-tree.notify") - local M = {} --- Create empty sub-tables if not present @@ -120,25 +118,32 @@ end ---@param u nvim_tree.config user supplied subset of config local function deprecated_config(u) if type(u.view) == "table" and u.view.hide_root_folder then - notify.info("view.hide_root_folder is deprecated, please set renderer.root_folder_label = false") + require("nvim-tree.notify").info( + "view.hide_root_folder is deprecated, please set renderer.root_folder_label = false" + ) end end ---@param u nvim_tree.config user supplied subset of config local function removed_config(u) if u.auto_close then - notify.warn("auto close feature has been removed: https://github.com/nvim-tree/nvim-tree.lua/wiki/Auto-Close") + require("nvim-tree.notify").warn( + "auto close feature has been removed: https://github.com/nvim-tree/nvim-tree.lua/wiki/Auto-Close" + ) u["auto_close"] = nil end if u.focus_empty_on_setup then - notify.warn("focus_empty_on_setup has been removed: https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup") + require("nvim-tree.notify").warn( + "focus_empty_on_setup has been removed: https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup" + ) u["focus_empty_on_setup"] = nil end if u.create_in_closed_folder then - notify.warn( - "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.") + require("nvim-tree.notify").warn( + "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." + ) end u["create_in_closed_folder"] = nil end From bb845a651e7db47bd246318a3819867a5bb5688b Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Mon, 30 Mar 2026 15:02:51 +1100 Subject: [PATCH 09/10] perf(#3257): inline require events notify --- lua/nvim-tree/events.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lua/nvim-tree/events.lua b/lua/nvim-tree/events.lua index 85e455ece52..ebabd2c4137 100644 --- a/lua/nvim-tree/events.lua +++ b/lua/nvim-tree/events.lua @@ -1,4 +1,3 @@ -local notify = require("nvim-tree.notify") local Event = require("nvim-tree._meta.api.events").Event local M = {} @@ -25,7 +24,7 @@ local function dispatch(event_name, payload) for _, handler in pairs(get_handlers(event_name)) do local success, error = pcall(handler, payload) if not success then - notify.error("Handler for event " .. event_name .. " errored. " .. vim.inspect(error)) + require("nvim-tree.notify").error("Handler for event " .. event_name .. " errored. " .. vim.inspect(error)) end end end From cc6bcda1686c9ad2268f075211422bec22ade7ab Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Mon, 30 Mar 2026 15:15:41 +1100 Subject: [PATCH 10/10] perf(#3257): inline require log notify --- lua/nvim-tree.lua | 2 +- lua/nvim-tree/log.lua | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 509a99bd1cb..c07c76cf7a4 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -281,7 +281,7 @@ function M.setup(config_user) manage_netrw() - require("nvim-tree.log").start() + log.start() if log.enabled("config") then log.line("config", "default config + user") diff --git a/lua/nvim-tree/log.lua b/lua/nvim-tree/log.lua index ff5686061fd..a564e3ca1bc 100644 --- a/lua/nvim-tree/log.lua +++ b/lua/nvim-tree/log.lua @@ -120,7 +120,9 @@ function M.start() if config.g.log.truncate then os.remove(file_path) end - require("nvim-tree.notify").debug("nvim-tree.lua logging to " .. file_path) + if config.g.notify.threshold <= vim.log.levels.DEBUG then + require("nvim-tree.notify").debug("nvim-tree.lua logging to " .. file_path) + end end end