Skip to content

Commit 4c096cd

Browse files
committed
perf(#3253): move requires inline
1 parent dc0fc5e commit 4c096cd

File tree

1 file changed

+42
-39
lines changed

1 file changed

+42
-39
lines changed

lua/nvim-tree.lua

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
local api = require("nvim-tree.api")
22
local log = require("nvim-tree.log")
3-
local view = require("nvim-tree.view")
4-
local utils = require("nvim-tree.utils")
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")
8-
local core = require("nvim-tree.core")
93
local notify = require("nvim-tree.notify")
104
local config = require("nvim-tree.config")
115

@@ -24,18 +18,16 @@ end
2418

2519
local function setup_autocommands()
2620
local augroup_id = vim.api.nvim_create_augroup("NvimTree", { clear = true })
27-
local function create_nvim_tree_autocmd(name, custom_opts)
28-
local default_opts = { group = augroup_id }
29-
vim.api.nvim_create_autocmd(name, vim.tbl_extend("force", default_opts, custom_opts))
30-
end
3121

3222
-- prevent new opened file from opening in the same window as nvim-tree
33-
create_nvim_tree_autocmd("BufWipeout", {
23+
vim.api.nvim_create_autocmd("BufWipeout", {
24+
group = augroup_id,
3425
pattern = "NvimTree_*",
3526
callback = function()
36-
if not utils.is_nvim_tree_buf(0) then
27+
if not require("nvim-tree.utils").is_nvim_tree_buf(0) then
3728
return
3829
end
30+
local view = require("nvim-tree.view")
3931
if config.g.actions.open_file.eject then
4032
view._prevent_buffer_override()
4133
else
@@ -45,33 +37,39 @@ local function setup_autocommands()
4537
})
4638

4739
if config.g.tab.sync.open then
48-
create_nvim_tree_autocmd("TabEnter", { callback = vim.schedule_wrap(function()
49-
require("nvim-tree.actions.tree.open").tab_enter()
50-
end) })
40+
vim.api.nvim_create_autocmd("TabEnter", {
41+
group = augroup_id,
42+
callback = vim.schedule_wrap(function()
43+
require("nvim-tree.actions.tree.open").tab_enter()
44+
end)
45+
})
5146
end
5247
if config.g.sync_root_with_cwd then
53-
create_nvim_tree_autocmd("DirChanged", {
48+
vim.api.nvim_create_autocmd("DirChanged", {
49+
group = augroup_id,
5450
callback = function()
55-
change_dir.fn(vim.loop.cwd())
51+
require("nvim-tree.actions.tree.change-dir").fn(vim.loop.cwd())
5652
end,
5753
})
5854
end
5955
if config.g.update_focused_file.enable then
60-
create_nvim_tree_autocmd("BufEnter", {
56+
vim.api.nvim_create_autocmd("BufEnter", {
57+
group = augroup_id,
6158
callback = function(event)
6259
local exclude = config.g.update_focused_file.exclude
6360
if type(exclude) == "function" and exclude(event) then
6461
return
6562
end
66-
utils.debounce("BufEnter:find_file", config.g.view.debounce_delay, function()
67-
find_file.fn()
63+
require("nvim-tree.utils").debounce("BufEnter:find_file", config.g.view.debounce_delay, function()
64+
require("nvim-tree.actions.tree.find-file").fn()
6865
end)
6966
end,
7067
})
7168
end
7269

7370
if config.g.hijack_directories.enable and (config.g.disable_netrw or config.g.hijack_netrw) then
74-
create_nvim_tree_autocmd({ "BufEnter", "BufNewFile" }, {
71+
vim.api.nvim_create_autocmd({ "BufEnter", "BufNewFile" }, {
72+
group = augroup_id,
7573
callback = function()
7674
require("nvim-tree.actions.tree.open").open_on_directory()
7775
end,
@@ -80,30 +78,31 @@ local function setup_autocommands()
8078
end
8179

8280
if config.g.view.centralize_selection then
83-
create_nvim_tree_autocmd("BufEnter", {
81+
vim.api.nvim_create_autocmd("BufEnter", {
82+
group = augroup_id,
8483
pattern = "NvimTree_*",
85-
callback = function()
86-
vim.schedule(function()
87-
vim.api.nvim_buf_call(0, function()
88-
local is_term_mode = vim.api.nvim_get_mode().mode == "t"
89-
if is_term_mode then
90-
return
91-
end
92-
vim.cmd([[norm! zz]])
93-
end)
84+
callback = vim.schedule_wrap(function()
85+
vim.api.nvim_buf_call(0, function()
86+
local is_term_mode = vim.api.nvim_get_mode().mode == "t"
87+
if is_term_mode then
88+
return
89+
end
90+
vim.cmd([[norm! zz]])
9491
end)
95-
end,
92+
end)
9693
})
9794
end
9895

9996
if config.g.diagnostics.enable then
100-
create_nvim_tree_autocmd("DiagnosticChanged", {
97+
vim.api.nvim_create_autocmd("DiagnosticChanged", {
98+
group = augroup_id,
10199
callback = function(ev)
102100
log.line("diagnostics", "DiagnosticChanged")
103101
require("nvim-tree.diagnostics").update_lsp(ev)
104102
end,
105103
})
106-
create_nvim_tree_autocmd("User", {
104+
vim.api.nvim_create_autocmd("User", {
105+
group = augroup_id,
107106
pattern = "CocDiagnosticChange",
108107
callback = function()
109108
log.line("diagnostics", "CocDiagnosticChange")
@@ -113,18 +112,20 @@ local function setup_autocommands()
113112
end
114113

115114
if config.g.view.float.enable and config.g.view.float.quit_on_focus_loss then
116-
create_nvim_tree_autocmd("WinLeave", {
115+
vim.api.nvim_create_autocmd("WinLeave", {
116+
group = augroup_id,
117117
pattern = "NvimTree_*",
118118
callback = function()
119-
if utils.is_nvim_tree_buf(0) then
120-
view.close()
119+
if require("nvim-tree.utils").is_nvim_tree_buf(0) then
120+
require("nvim-tree.view").close()
121121
end
122122
end,
123123
})
124124
end
125125

126126
-- Handles event dispatch when tree is closed by `:q`
127-
create_nvim_tree_autocmd("WinClosed", {
127+
vim.api.nvim_create_autocmd("WinClosed", {
128+
group = augroup_id,
128129
pattern = "*",
129130
---@param ev vim.api.keyset.create_autocmd.callback_args
130131
callback = function(ev)
@@ -138,10 +139,12 @@ local function setup_autocommands()
138139
})
139140

140141
-- renderer.full name
141-
full_name.setup_autocommands()
142+
require("nvim-tree.renderer.components.full-name").setup_autocommands()
142143
end
143144

144145
function M.purge_all_state()
146+
local view = require("nvim-tree.view")
147+
local core = require("nvim-tree.core")
145148
view.close_all_tabs()
146149
view.abandon_all_windows()
147150
local explorer = core.get_explorer()

0 commit comments

Comments
 (0)