Skip to content

Commit f779aba

Browse files
refactor: improve API readability and tidy actions submodules (#2593)
* refactor: improve API readability, tidy actions modules * Apply requested changes * `actions/reloaders/reloaders.lua` -> `actions/reloaders.lua` --------- Co-authored-by: Alexander Courtis <[email protected]>
1 parent dc839a7 commit f779aba

File tree

20 files changed

+217
-154
lines changed

20 files changed

+217
-154
lines changed

lua/nvim-tree.lua

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ local renderer = require "nvim-tree.renderer"
55
local view = require "nvim-tree.view"
66
local commands = require "nvim-tree.commands"
77
local utils = require "nvim-tree.utils"
8-
local change_dir = require "nvim-tree.actions.root.change-dir"
8+
local actions = require "nvim-tree.actions"
99
local legacy = require "nvim-tree.legacy"
1010
local core = require "nvim-tree.core"
11-
local reloaders = require "nvim-tree.actions.reloaders.reloaders"
1211
local git = require "nvim-tree.git"
1312
local filters = require "nvim-tree.explorer.filters"
1413
local modified = require "nvim-tree.modified"
15-
local find_file = require "nvim-tree.actions.tree.find-file"
1614
local events = require "nvim-tree.events"
1715
local notify = require "nvim-tree.notify"
1816

@@ -51,7 +49,7 @@ function M.change_root(path, bufnr)
5149
-- test if in vim_cwd
5250
if utils.path_relative(path, vim_cwd) ~= path then
5351
if vim_cwd ~= cwd then
54-
change_dir.fn(vim_cwd)
52+
actions.root.change_dir.fn(vim_cwd)
5553
end
5654
return
5755
end
@@ -62,19 +60,19 @@ function M.change_root(path, bufnr)
6260

6361
-- otherwise test M.init_root
6462
if _config.prefer_startup_root and utils.path_relative(path, M.init_root) ~= path then
65-
change_dir.fn(M.init_root)
63+
actions.root.change_dir.fn(M.init_root)
6664
return
6765
end
6866
-- otherwise root_dirs
6967
for _, dir in pairs(_config.root_dirs) do
7068
dir = vim.fn.fnamemodify(dir, ":p")
7169
if utils.path_relative(path, dir) ~= path then
72-
change_dir.fn(dir)
70+
actions.root.change_dir.fn(dir)
7371
return
7472
end
7573
end
7674
-- finally fall back to the folder containing the file
77-
change_dir.fn(vim.fn.fnamemodify(path, ":p:h"))
75+
actions.root.change_dir.fn(vim.fn.fnamemodify(path, ":p:h"))
7876
end
7977

8078
function M.tab_enter()
@@ -87,7 +85,7 @@ function M.tab_enter()
8785
end
8886
end
8987
view.open { focus_tree = false }
90-
require("nvim-tree.renderer").draw()
88+
renderer.draw()
9189
end
9290
end
9391

@@ -103,7 +101,7 @@ function M.open_on_directory()
103101
return
104102
end
105103

106-
change_dir.force_dirchange(bufname, true)
104+
actions.root.change_dir.force_dirchange(bufname, true)
107105
end
108106

109107
function M.reset_highlight()
@@ -154,11 +152,11 @@ end
154152
---@param name string|nil
155153
function M.change_dir(name)
156154
if name then
157-
change_dir.fn(name)
155+
actions.root.change_dir.fn(name)
158156
end
159157

160158
if _config.update_focused_file.enable then
161-
find_file.fn()
159+
actions.tree.find_file.fn()
162160
end
163161
end
164162

@@ -191,7 +189,7 @@ local function setup_autocommands(opts)
191189
create_nvim_tree_autocmd("BufWritePost", {
192190
callback = function()
193191
if opts.auto_reload_on_write and not opts.filesystem_watchers.enable then
194-
reloaders.reload_explorer()
192+
actions.reloaders.reload_explorer()
195193
end
196194
end,
197195
})
@@ -201,7 +199,7 @@ local function setup_autocommands(opts)
201199
-- update opened file buffers
202200
if (filters.config.filter_no_buffer or renderer.config.highlight_opened_files ~= "none") and vim.bo[data.buf].buftype == "" then
203201
utils.debounce("Buf:filter_buffer", opts.view.debounce_delay, function()
204-
reloaders.reload_explorer()
202+
actions.reloaders.reload_explorer()
205203
end)
206204
end
207205
end,
@@ -212,7 +210,7 @@ local function setup_autocommands(opts)
212210
-- update opened file buffers
213211
if (filters.config.filter_no_buffer or renderer.config.highlight_opened_files ~= "none") and vim.bo[data.buf].buftype == "" then
214212
utils.debounce("Buf:filter_buffer", opts.view.debounce_delay, function()
215-
reloaders.reload_explorer(nil, data.buf)
213+
actions.reloaders.reload_explorer(nil, data.buf)
216214
end)
217215
end
218216
end,
@@ -222,7 +220,7 @@ local function setup_autocommands(opts)
222220
pattern = { "FugitiveChanged", "NeogitStatusRefreshed" },
223221
callback = function()
224222
if not opts.filesystem_watchers.enable and opts.git.enable then
225-
reloaders.reload_git()
223+
actions.reloaders.reload_git()
226224
end
227225
end,
228226
})
@@ -251,7 +249,7 @@ local function setup_autocommands(opts)
251249
create_nvim_tree_autocmd("BufEnter", {
252250
callback = function()
253251
utils.debounce("BufEnter:find_file", opts.view.debounce_delay, function()
254-
find_file.fn()
252+
actions.tree.find_file.fn()
255253
end)
256254
end,
257255
})
@@ -266,7 +264,7 @@ local function setup_autocommands(opts)
266264
callback = function()
267265
if utils.is_nvim_tree_buf(0) then
268266
if vim.fn.getcwd() ~= core.get_cwd() or (opts.reload_on_bufenter and not opts.filesystem_watchers.enable) then
269-
reloaders.reload_explorer()
267+
actions.reloaders.reload_explorer()
270268
end
271269
end
272270
end,
@@ -317,7 +315,7 @@ local function setup_autocommands(opts)
317315
callback = function()
318316
utils.debounce("Buf:modified", opts.view.debounce_delay, function()
319317
modified.reload()
320-
reloaders.reload_explorer()
318+
actions.reloaders.reload_explorer()
321319
end)
322320
end,
323321
})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
local M = {}
2+
3+
M.find_file = require "nvim-tree.actions.finders.find-file"
4+
M.search_node = require "nvim-tree.actions.finders.search-node"
5+
6+
return M

lua/nvim-tree/actions/fs/copy-paste.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local core = require "nvim-tree.core"
55
local events = require "nvim-tree.events"
66
local notify = require "nvim-tree.notify"
77
local renderer = require "nvim-tree.renderer"
8-
local reloaders = require "nvim-tree.actions.reloaders.reloaders"
8+
local reloaders = require "nvim-tree.actions.reloaders"
99

1010
local HL_POSITION = require("nvim-tree.enum").HL_POSITION
1111

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
local M = {}
2+
3+
M.copy_paste = require "nvim-tree.actions.fs.copy-paste"
4+
M.create_file = require "nvim-tree.actions.fs.create-file"
5+
M.remove_file = require "nvim-tree.actions.fs.remove-file"
6+
M.rename_file = require "nvim-tree.actions.fs.rename-file"
7+
M.trash = require "nvim-tree.actions.fs.trash"
8+
9+
function M.setup(opts)
10+
M.copy_paste.setup(opts)
11+
M.remove_file.setup(opts)
12+
M.rename_file.setup(opts)
13+
M.trash.setup(opts)
14+
end
15+
16+
return M

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function M.fn(node)
112112
local function do_remove()
113113
M.remove(node)
114114
if not M.config.filesystem_watchers.enable then
115-
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
115+
require("nvim-tree.actions.reloaders").reload_explorer()
116116
end
117117
end
118118

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function M.fn(default_modifier)
102102

103103
M.rename(node, prepend .. new_file_path .. append)
104104
if not M.config.filesystem_watchers.enable then
105-
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
105+
require("nvim-tree.actions.reloaders").reload_explorer()
106106
end
107107

108108
find_file(utils.path_remove_trailing(new_file_path))

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local lib = require "nvim-tree.lib"
22
local notify = require "nvim-tree.notify"
3+
local reloaders = require "nvim-tree.actions.reloaders"
34

45
local M = {
56
config = {},
@@ -59,7 +60,7 @@ function M.remove(node)
5960
end
6061
events._dispatch_folder_removed(node.absolute_path)
6162
if not M.config.filesystem_watchers.enable then
62-
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
63+
reloaders.reload_explorer()
6364
end
6465
end)
6566
else
@@ -72,7 +73,7 @@ function M.remove(node)
7273
events._dispatch_file_removed(node.absolute_path)
7374
clear_buffer(node.absolute_path)
7475
if not M.config.filesystem_watchers.enable then
75-
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
76+
reloaders.reload_explorer()
7677
end
7778
end)
7879
end

lua/nvim-tree/actions/init.lua

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
local M = {}
22

3+
M.finders = require "nvim-tree.actions.finders"
4+
M.fs = require "nvim-tree.actions.fs"
5+
M.moves = require "nvim-tree.actions.moves"
6+
M.node = require "nvim-tree.actions.node"
7+
M.reloaders = require "nvim-tree.actions.reloaders"
8+
M.root = require "nvim-tree.actions.root"
9+
M.tree = require "nvim-tree.actions.tree"
10+
311
function M.setup(opts)
4-
require("nvim-tree.actions.fs.trash").setup(opts)
5-
require("nvim-tree.actions.node.system-open").setup(opts)
6-
require("nvim-tree.actions.node.file-popup").setup(opts)
7-
require("nvim-tree.actions.node.open-file").setup(opts)
8-
require("nvim-tree.actions.root.change-dir").setup(opts)
9-
require("nvim-tree.actions.fs.rename-file").setup(opts)
10-
require("nvim-tree.actions.fs.remove-file").setup(opts)
11-
require("nvim-tree.actions.fs.copy-paste").setup(opts)
12-
require("nvim-tree.actions.tree-modifiers.expand-all").setup(opts)
13-
require("nvim-tree.actions.tree.find-file").setup(opts)
14-
require("nvim-tree.actions.tree.open").setup(opts)
15-
require("nvim-tree.actions.tree.toggle").setup(opts)
12+
M.fs.setup(opts)
13+
M.node.setup(opts)
14+
M.root.setup(opts)
15+
M.tree.setup(opts)
1616
end
1717

1818
return M

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
local M = {}
2+
3+
M.item = require "nvim-tree.actions.moves.item"
4+
M.parent = require "nvim-tree.actions.moves.parent"
5+
M.sibling = require "nvim-tree.actions.moves.sibling"
6+
7+
return M

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
local M = {}
2+
3+
M.file_popup = require "nvim-tree.actions.node.file-popup"
4+
M.open_file = require "nvim-tree.actions.node.open-file"
5+
M.run_command = require "nvim-tree.actions.node.run-command"
6+
M.system_open = require "nvim-tree.actions.node.system-open"
7+
8+
function M.setup(opts)
9+
require("nvim-tree.actions.node.system-open").setup(opts)
10+
require("nvim-tree.actions.node.file-popup").setup(opts)
11+
require("nvim-tree.actions.node.open-file").setup(opts)
12+
end
13+
14+
return M

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
local M = {}
2+
3+
M.change_dir = require "nvim-tree.actions.root.change-dir"
4+
M.dir_up = require "nvim-tree.actions.root.dir-up"
5+
6+
function M.setup(opts)
7+
M.change_dir.setup(opts)
8+
end
9+
10+
return M

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
local M = {}
2+
3+
M.find_file = require "nvim-tree.actions.tree.find-file"
4+
M.modifiers = require "nvim-tree.actions.tree.modifiers"
5+
M.open = require "nvim-tree.actions.tree.open"
6+
M.toggle = require "nvim-tree.actions.tree.toggle"
7+
8+
function M.setup(opts)
9+
M.find_file.setup(opts)
10+
M.modifiers.setup(opts)
11+
M.open.setup(opts)
12+
M.toggle.setup(opts)
13+
end
14+
15+
return M
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
local M = {}
2+
3+
M.collapse_all = require "nvim-tree.actions.tree.modifiers.collapse-all"
4+
M.expand_all = require "nvim-tree.actions.tree.modifiers.expand-all"
5+
M.toggles = require "nvim-tree.actions.tree.modifiers.toggles"
6+
7+
function M.setup(opts)
8+
M.expand_all.setup(opts)
9+
end
10+
11+
return M

lua/nvim-tree/actions/tree-modifiers/toggles.lua renamed to lua/nvim-tree/actions/tree/modifiers/toggles.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local lib = require "nvim-tree.lib"
22
local utils = require "nvim-tree.utils"
33
local filters = require "nvim-tree.explorer.filters"
4-
local reloaders = require "nvim-tree.actions.reloaders.reloaders"
4+
local reloaders = require "nvim-tree.actions.reloaders"
55

66
local M = {}
77

0 commit comments

Comments
 (0)