Skip to content

Commit 43a3bb4

Browse files
authored
perf(#3257): remove setup for actions modules, full-name and explorer (#3299)
* perf(#3257): remove remove-file setup * perf(#3257): remove rename-file setup * perf(#3257): remove trash setup * perf(#3257): remove actions.fs init * perf(#3257): remove file-popup setup * perf(#3257): remove open-file setup * perf(#3257): remove system-open setup * perf(#3257): remove open-file setup * perf(#3257): remove actions.node init * perf(#3257): remove change-dir setup * perf(#3257): remove find-file setup * perf(#3257): remove open setup * perf(#3257): remove toggle setup * perf(#3257): remove resize setup * perf(#3257): remove finders init * perf(#3257): remove moves init * perf(#3257): remove tree init * perf(#3257): remove explorer setup * perf(#3257): view uses config.g * perf(#3257): move os from utils to config, removing requires * perf(#3257): move os from utils to config, removing requires * perf(#3257): move os from utils to config, removing requires * perf(#3257): remove watch setup * perf(#3257): remove notify setup * perf(#3257): remove full-name setup * perf(#3257): remove padding setup * Revert "perf(#3257): remove padding setup" This reverts commit 862db03.
1 parent 6eaf74c commit 43a3bb4

29 files changed

+275
-391
lines changed

lua/nvim-tree.lua

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ local api = require("nvim-tree.api")
22
local log = require("nvim-tree.log")
33
local view = require("nvim-tree.view")
44
local utils = require("nvim-tree.utils")
5-
local actions = require("nvim-tree.actions")
5+
local find_file = require("nvim-tree.actions.tree.find-file")
6+
local change_dir = require("nvim-tree.actions.tree.change-dir")
7+
local full_name = require("nvim-tree.renderer.components.full-name")
68
local core = require("nvim-tree.core")
79
local notify = require("nvim-tree.notify")
810
local config = require("nvim-tree.config")
@@ -169,7 +171,7 @@ local function setup_autocommands()
169171
if config.g.sync_root_with_cwd then
170172
create_nvim_tree_autocmd("DirChanged", {
171173
callback = function()
172-
actions.tree.change_dir.fn(vim.loop.cwd())
174+
change_dir.fn(vim.loop.cwd())
173175
end,
174176
})
175177
end
@@ -181,7 +183,7 @@ local function setup_autocommands()
181183
return
182184
end
183185
utils.debounce("BufEnter:find_file", config.g.view.debounce_delay, function()
184-
actions.tree.find_file.fn()
186+
find_file.fn()
185187
end)
186188
end,
187189
})
@@ -248,6 +250,9 @@ local function setup_autocommands()
248250
end
249251
end,
250252
})
253+
254+
-- renderer.full name
255+
full_name.setup_autocommands()
251256
end
252257

253258
function M.purge_all_state()
@@ -276,18 +281,14 @@ function M.setup(config_user)
276281

277282
manage_netrw()
278283

279-
require("nvim-tree.notify").setup(config.g)
280284
require("nvim-tree.log").setup(config.g)
281285

282286
if log.enabled("config") then
283287
log.line("config", "default config + user")
284288
log.raw("config", "%s\n", vim.inspect(config.g))
285289
end
286290

287-
require("nvim-tree.actions").setup(config.g)
288291
require("nvim-tree.appearance").setup()
289-
require("nvim-tree.explorer"):setup(config.g)
290-
require("nvim-tree.explorer.watch").setup(config.g)
291292
require("nvim-tree.view").setup(config.g)
292293
require("nvim-tree.renderer.components").setup(config.g)
293294

lua/nvim-tree/actions/finders/init.lua

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

lua/nvim-tree/actions/fs/init.lua

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

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

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
local core = require("nvim-tree.core")
22
local utils = require("nvim-tree.utils")
33
local events = require("nvim-tree.events")
4-
local view = require("nvim-tree.view")
54
local lib = require("nvim-tree.lib")
65
local notify = require("nvim-tree.notify")
6+
local config = require("nvim-tree.config")
77

88
local DirectoryLinkNode = require("nvim-tree.node.directory-link")
99
local DirectoryNode = require("nvim-tree.node.directory")
@@ -18,7 +18,7 @@ local M = {
1818
local function close_windows(windows)
1919
-- When floating, prevent closing the last non-floating window.
2020
-- For details see #2503, #3187.
21-
if view.View.float.enable then
21+
if config.g.view.float.enable then
2222
local non_float_count = 0
2323
for _, win in ipairs(vim.api.nvim_list_wins()) do
2424
if vim.api.nvim_win_get_config(win).relative == "" then
@@ -43,15 +43,15 @@ local function clear_buffer(absolute_path)
4343
for _, buf in pairs(bufs) do
4444
if buf.name == absolute_path then
4545
local tree_winnr = vim.api.nvim_get_current_win()
46-
if buf.hidden == 0 and (#bufs > 1 or view.View.float.enable) then
46+
if buf.hidden == 0 and (#bufs > 1 or config.g.view.float.enable) then
4747
vim.api.nvim_set_current_win(buf.windows[1])
4848
vim.cmd(":bn")
4949
end
5050
vim.api.nvim_buf_delete(buf.bufnr, { force = true })
51-
if not view.View.float.quit_on_focus_loss then
51+
if not config.g.view.float.quit_on_focus_loss then
5252
vim.api.nvim_set_current_win(tree_winnr)
5353
end
54-
if M.config.actions.remove_file.close_window then
54+
if config.g.actions.remove_file.close_window then
5555
close_windows(buf.windows)
5656
end
5757
return
@@ -141,18 +141,18 @@ local function remove_one(node)
141141
notify.info(notify.render_path(node.absolute_path) .. " was properly removed.")
142142
end
143143
local explorer = core.get_explorer()
144-
if not M.config.filesystem_watchers.enable and explorer then
144+
if not config.g.filesystem_watchers.enable and explorer then
145145
explorer:reload_explorer()
146146
end
147147
end
148148

149-
if M.config.ui.confirm.remove then
149+
if config.g.ui.confirm.remove then
150150
local prompt_select = "Remove " .. node.name .. "?"
151-
local prompt_input, items_short, items_long = utils.confirm_prompt(prompt_select, M.config.ui.confirm.default_yes)
151+
local prompt_input, items_short, items_long = utils.confirm_prompt(prompt_select, config.g.ui.confirm.default_yes)
152152

153153
lib.prompt(prompt_input, prompt_select, items_short, items_long, "nvimtree_remove", function(item_short)
154154
utils.clear_prompt()
155-
if item_short == "y" or item_short == (M.config.ui.confirm.default_yes and "") then
155+
if item_short == "y" or item_short == (config.g.ui.confirm.default_yes and "") then
156156
do_remove()
157157
end
158158
end)
@@ -181,18 +181,18 @@ local function remove_many(nodes)
181181
notify.info(string.format("%d nodes properly removed.", removed))
182182
end
183183
local explorer = core.get_explorer()
184-
if not M.config.filesystem_watchers.enable and explorer then
184+
if not config.g.filesystem_watchers.enable and explorer then
185185
explorer:reload_explorer()
186186
end
187187
end
188188

189-
if M.config.ui.confirm.remove then
189+
if config.g.ui.confirm.remove then
190190
local prompt_select = string.format("Remove %d selected?", #nodes)
191-
local prompt_input, items_short, items_long = utils.confirm_prompt(prompt_select, M.config.ui.confirm.default_yes)
191+
local prompt_input, items_short, items_long = utils.confirm_prompt(prompt_select, config.g.ui.confirm.default_yes)
192192

193193
lib.prompt(prompt_input, prompt_select, items_short, items_long, "nvimtree_remove", function(item_short)
194194
utils.clear_prompt()
195-
if item_short == "y" or item_short == (M.config.ui.confirm.default_yes and "") then
195+
if item_short == "y" or item_short == (config.g.ui.confirm.default_yes and "") then
196196
execute()
197197
end
198198
end)
@@ -210,10 +210,4 @@ function M.fn(node_or_nodes)
210210
end
211211
end
212212

213-
function M.setup(opts)
214-
M.config.ui = opts.ui
215-
M.config.actions = opts.actions
216-
M.config.filesystem_watchers = opts.filesystem_watchers
217-
end
218-
219213
return M

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ local core = require("nvim-tree.core")
22
local utils = require("nvim-tree.utils")
33
local events = require("nvim-tree.events")
44
local notify = require("nvim-tree.notify")
5+
local config = require("nvim-tree.config")
56

67
local find_file = require("nvim-tree.actions.finders.find-file").fn
78

@@ -33,7 +34,7 @@ local function err_fmt(from, to, reason)
3334
end
3435

3536
local function rename_file_exists(node, to)
36-
if not utils.is_macos then
37+
if not config.os.macos then
3738
return utils.file_exists(to)
3839
end
3940

@@ -163,7 +164,7 @@ local function prompt_to_rename(node, modifier)
163164
local full_new_path = prepend .. new_file_path .. append
164165

165166
M.rename(node, full_new_path)
166-
if not M.config.filesystem_watchers.enable then
167+
if not config.g.filesystem_watchers.enable then
167168
explorer:reload_explorer()
168169
end
169170

@@ -192,7 +193,7 @@ function M.rename_full(node)
192193
end
193194

194195
function M.setup(opts)
195-
M.config.filesystem_watchers = opts.filesystem_watchers
196+
config.g.filesystem_watchers = opts.filesystem_watchers
196197
end
197198

198199
return M

lua/nvim-tree/actions/fs/trash.lua

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local lib = require("nvim-tree.lib")
33
local notify = require("nvim-tree.notify")
44
local utils = require("nvim-tree.utils")
55
local events = require("nvim-tree.events")
6+
local config = require("nvim-tree.config")
67

78
local DirectoryLinkNode = require("nvim-tree.node.directory-link")
89
local DirectoryNode = require("nvim-tree.node.directory")
@@ -32,9 +33,9 @@ end
3233

3334
---@param node Node
3435
function M.remove(node)
35-
local binary = M.config.trash.cmd:gsub(" .*$", "")
36+
local binary = config.g.trash.cmd:gsub(" .*$", "")
3637
if vim.fn.executable(binary) == 0 then
37-
notify.warn(string.format("trash.cmd '%s' is not an executable.", M.config.trash.cmd))
38+
notify.warn(string.format("trash.cmd '%s' is not an executable.", config.g.trash.cmd))
3839
return
3940
end
4041

@@ -45,8 +46,8 @@ function M.remove(node)
4546

4647
-- trashes a path (file or folder)
4748
local function trash_path(on_exit)
48-
local need_sync_wait = utils.is_windows
49-
local job = vim.fn.jobstart(M.config.trash.cmd .. " " .. vim.fn.shellescape(node.absolute_path), {
49+
local need_sync_wait = config.os.windows
50+
local job = vim.fn.jobstart(config.g.trash.cmd .. " " .. vim.fn.shellescape(node.absolute_path), {
5051
detach = not need_sync_wait,
5152
on_exit = on_exit,
5253
on_stderr = on_stderr,
@@ -65,7 +66,7 @@ function M.remove(node)
6566
return
6667
end
6768
events._dispatch_folder_removed(node.absolute_path)
68-
if not M.config.filesystem_watchers.enable and explorer then
69+
if not config.g.filesystem_watchers.enable and explorer then
6970
explorer:reload_explorer()
7071
end
7172
end)
@@ -78,7 +79,7 @@ function M.remove(node)
7879
end
7980
events._dispatch_file_removed(node.absolute_path)
8081
clear_buffer(node.absolute_path)
81-
if not M.config.filesystem_watchers.enable and explorer then
82+
if not config.g.filesystem_watchers.enable and explorer then
8283
explorer:reload_explorer()
8384
end
8485
end)
@@ -96,13 +97,13 @@ local function trash_one(node)
9697
M.remove(node)
9798
end
9899

99-
if M.config.ui.confirm.trash then
100+
if config.g.ui.confirm.trash then
100101
local prompt_select = "Trash " .. node.name .. "?"
101-
local prompt_input, items_short, items_long = utils.confirm_prompt(prompt_select, M.config.ui.confirm.default_yes)
102+
local prompt_input, items_short, items_long = utils.confirm_prompt(prompt_select, config.g.ui.confirm.default_yes)
102103

103104
lib.prompt(prompt_input, prompt_select, items_short, items_long, "nvimtree_trash", function(item_short)
104105
utils.clear_prompt()
105-
if item_short == "y" or item_short == (M.config.ui.confirm.default_yes and "") then
106+
if item_short == "y" or item_short == (config.g.ui.confirm.default_yes and "") then
106107
do_trash()
107108
end
108109
end)
@@ -128,13 +129,13 @@ local function trash_many(nodes)
128129
end
129130
end
130131

131-
if M.config.ui.confirm.trash then
132+
if config.g.ui.confirm.trash then
132133
local prompt_select = string.format("Trash %d selected?", #nodes)
133-
local prompt_input, items_short, items_long = utils.confirm_prompt(prompt_select, M.config.ui.confirm.default_yes)
134+
local prompt_input, items_short, items_long = utils.confirm_prompt(prompt_select, config.g.ui.confirm.default_yes)
134135

135136
lib.prompt(prompt_input, prompt_select, items_short, items_long, "nvimtree_trash", function(item_short)
136137
utils.clear_prompt()
137-
if item_short == "y" or item_short == (M.config.ui.confirm.default_yes and "") then
138+
if item_short == "y" or item_short == (config.g.ui.confirm.default_yes and "") then
138139
execute()
139140
end
140141
end)
@@ -152,10 +153,4 @@ function M.fn(node_or_nodes)
152153
end
153154
end
154155

155-
function M.setup(opts)
156-
M.config.ui = opts.ui
157-
M.config.trash = opts.trash
158-
M.config.filesystem_watchers = opts.filesystem_watchers
159-
end
160-
161156
return M

lua/nvim-tree/actions/init.lua

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

lua/nvim-tree/actions/moves/init.lua

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

lua/nvim-tree/actions/node/file-popup.lua

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local utils = require("nvim-tree.utils")
2+
local config = require("nvim-tree.config")
23

34
local M = {}
45

@@ -38,7 +39,7 @@ local function setup_window(node)
3839
local max_width = vim.fn.max(vim.tbl_map(function(n)
3940
return #n
4041
end, lines))
41-
local open_win_config = vim.tbl_extend("force", M.open_win_config, {
42+
local open_win_config = vim.tbl_extend("force", config.g.actions.file_popup.open_win_config, {
4243
width = max_width + 1,
4344
height = #lines,
4445
noautocmd = true,
@@ -89,8 +90,4 @@ function M.toggle_file_info(node)
8990
})
9091
end
9192

92-
function M.setup(opts)
93-
M.open_win_config = opts.actions.file_popup.open_win_config
94-
end
95-
9693
return M

lua/nvim-tree/actions/node/init.lua

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

0 commit comments

Comments
 (0)