From 31481abe3e6aecc7a8aac17424cc7ef4aa328d2f Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 28 Mar 2026 11:09:06 +1100 Subject: [PATCH 1/4] perf(#3257): replace view.initial_width with a function --- lua/nvim-tree/view.lua | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index 6e36c8e50da..9b84feff2ef 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -116,7 +116,7 @@ local function create_buffer(bufnr) events._dispatch_tree_attached_post(M.get_bufnr()) end ----@param size (fun():integer)|integer|string +---@param size nvim_tree.config.view.width.spec ---@return integer local function get_size(size) if type(size) == "number" then @@ -129,6 +129,16 @@ local function get_size(size) return math.floor(vim.o.columns * percent_as_decimal) end +---Return the width as per config +---@return integer +local function initial_width() + if type(config.g.view.width) == "table" then + return get_size(config.g.view.width.min or DEFAULT_MIN_WIDTH) + else + return get_size(config.g.view.width --[[@as nvim_tree.config.view.width.spec]]) + end +end + ---@param size (fun():integer)|integer|nil ---@return integer local function get_width(size) @@ -317,7 +327,7 @@ local function grow() padding = padding + wininfo[1].textoff end - local final_width = M.View.initial_width + local final_width = initial_width() local max_width = get_width(M.View.max_width) if max_width == -1 then max_width = math.huge @@ -606,7 +616,7 @@ function M.configure_width(width) M.configure_width(config.g.view.width) else -- otherwise - restore initial width - M.View.width = M.View.initial_width + M.View.width = initial_width() end else M.View.adaptive_size = false @@ -624,8 +634,6 @@ function M.setup(opts) M.View.winopts.signcolumn = options.signcolumn M.configure_width(options.width) - - M.View.initial_width = get_width() end return M From ae58f0ef797ba0ff2dd903ef537abc3a1e9abd47 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 28 Mar 2026 11:33:24 +1100 Subject: [PATCH 2/4] perf(#3257): remove winopts from view setup --- lua/nvim-tree/view.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index 9b84feff2ef..04289dafa63 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -164,6 +164,12 @@ end local function set_window_options_and_buffer() pcall(vim.api.nvim_command, "buffer " .. M.get_bufnr()) + M.View.winopts.cursorline = config.g.view.cursorline + M.View.winopts.cursorlineopt = config.g.view.cursorlineopt + M.View.winopts.number = config.g.view.number + M.View.winopts.relativenumber = config.g.view.relativenumber + M.View.winopts.signcolumn = config.g.view.signcolumn + if vim.fn.has("nvim-0.10") == 1 then local eventignore = vim.api.nvim_get_option_value("eventignore", {}) vim.api.nvim_set_option_value("eventignore", "all", {}) @@ -627,12 +633,6 @@ end ---@param opts nvim_tree.config function M.setup(opts) local options = opts.view or {} - M.View.winopts.cursorline = options.cursorline - M.View.winopts.cursorlineopt = options.cursorlineopt - M.View.winopts.number = options.number - M.View.winopts.relativenumber = options.relativenumber - M.View.winopts.signcolumn = options.signcolumn - M.configure_width(options.width) end From d361be831ce6e9de9a36d08e3b4b1be7f740a9f6 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 28 Mar 2026 11:51:18 +1100 Subject: [PATCH 3/4] perf(#3257): remove view setup --- lua/nvim-tree.lua | 1 - lua/nvim-tree/view.lua | 66 ++++++++++++++++++++++-------------------- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index f29005e5961..aa9b08a2c0b 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.view").setup(config.g) require("nvim-tree.renderer.components").setup(config.g) setup_autocommands() diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index 04289dafa63..68be68a419e 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -139,6 +139,31 @@ local function initial_width() end end +---Configure width-related config +---@param width string|function|number|table|nil +function M.configure_width(width) + log.line("dev", "configure_width") + if type(width) == "table" then + M.View.adaptive_size = true + M.View.width = width.min or DEFAULT_MIN_WIDTH + M.View.max_width = width.max or DEFAULT_MAX_WIDTH + local lines_excluded = width.lines_excluded or DEFAULT_LINES_EXCLUDED + M.View.root_excluded = vim.tbl_contains(lines_excluded, "root") + M.View.padding = width.padding or DEFAULT_PADDING + elseif width == nil then + if config.g.view.width ~= nil then + -- if we had input config - fallback to it + M.configure_width(config.g.view.width) + else + -- otherwise - restore initial width + M.View.width = initial_width() + end + else + M.View.adaptive_size = false + M.View.width = width + end +end + ---@param size (fun():integer)|integer|nil ---@return integer local function get_width(size) @@ -198,7 +223,7 @@ local function open_win_config() if type(config.g.view.float.open_win_config) == "function" then return config.g.view.float.open_win_config() else - return config.g.view.float.open_win_config --[[ @as vim.api.keyset.win_config ]] + return config.g.view.float.open_win_config --[[@as vim.api.keyset.win_config]] end end @@ -305,6 +330,10 @@ function M.open(options) return end + if not M.View.width then + M.configure_width(config.g.view.width) + end + local profile = log.profile_start("view open") events._dispatch_on_tree_pre_open() @@ -420,6 +449,11 @@ end ---@param opts OpenInWinOpts|nil function M.open_in_win(opts) opts = opts or { hijack_current_buf = true, resize = true } + + if not M.View.width then + M.configure_width(config.g.view.width) + end + events._dispatch_on_tree_pre_open() if opts.winid and vim.api.nvim_win_is_valid(opts.winid) then vim.api.nvim_set_current_win(opts.winid) @@ -606,34 +640,4 @@ function M.is_width_determined() return type(M.View.width) ~= "function" end ----Configure width-related config ----@param width string|function|number|table|nil -function M.configure_width(width) - if type(width) == "table" then - M.View.adaptive_size = true - M.View.width = width.min or DEFAULT_MIN_WIDTH - M.View.max_width = width.max or DEFAULT_MAX_WIDTH - local lines_excluded = width.lines_excluded or DEFAULT_LINES_EXCLUDED - M.View.root_excluded = vim.tbl_contains(lines_excluded, "root") - M.View.padding = width.padding or DEFAULT_PADDING - elseif width == nil then - if config.g.view.width ~= nil then - -- if we had input config - fallback to it - M.configure_width(config.g.view.width) - else - -- otherwise - restore initial width - M.View.width = initial_width() - end - else - M.View.adaptive_size = false - M.View.width = width - end -end - ----@param opts nvim_tree.config -function M.setup(opts) - local options = opts.view or {} - M.configure_width(options.width) -end - return M From 39e446aa4d01073978b9f6cfbee334fa1a2bbdd5 Mon Sep 17 00:00:00 2001 From: Alexander Courtis Date: Sat, 28 Mar 2026 12:29:22 +1100 Subject: [PATCH 4/4] perf(#3257): remove view setup --- lua/nvim-tree/view.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/nvim-tree/view.lua b/lua/nvim-tree/view.lua index 68be68a419e..f0fc8a21faa 100644 --- a/lua/nvim-tree/view.lua +++ b/lua/nvim-tree/view.lua @@ -142,7 +142,6 @@ end ---Configure width-related config ---@param width string|function|number|table|nil function M.configure_width(width) - log.line("dev", "configure_width") if type(width) == "table" then M.View.adaptive_size = true M.View.width = width.min or DEFAULT_MIN_WIDTH