Skip to content

refactor(actions): move actions into semantic modules #1410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ local colors = require "nvim-tree.colors"
local renderer = require "nvim-tree.renderer"
local view = require "nvim-tree.view"
local utils = require "nvim-tree.utils"
local change_dir = require "nvim-tree.actions.change-dir"
local change_dir = require "nvim-tree.actions.root.change-dir"
local legacy = require "nvim-tree.legacy"
local core = require "nvim-tree.core"
local reloaders = require "nvim-tree.actions.reloaders"
local copy_paste = require "nvim-tree.actions.copy-paste"
local collapse_all = require "nvim-tree.actions.collapse-all"
local reloaders = require "nvim-tree.actions.reloaders.reloaders"
local copy_paste = require "nvim-tree.actions.fs.copy-paste"
local collapse_all = require "nvim-tree.actions.tree-modifiers.collapse-all"
local git = require "nvim-tree.git"

local _config = {}
Expand Down Expand Up @@ -116,7 +116,7 @@ function M.open_replacing_current_buffer(cwd)
end
view.open_in_current_win { hijack_current_buf = false, resize = false }
require("nvim-tree.renderer").draw()
require("nvim-tree.actions.find-file").fn(bufname)
require("nvim-tree.actions.finders.find-file").fn(bufname)
end

function M.tab_change()
Expand Down Expand Up @@ -163,7 +163,7 @@ function M.find_file(with_open, bufnr, bang)
if bang or _config.update_focused_file.update_root then
M.change_root(filepath, bufnr)
end
require("nvim-tree.actions.find-file").fn(filepath)
require("nvim-tree.actions.finders.find-file").fn(filepath)
end)
end

Expand Down
80 changes: 44 additions & 36 deletions lua/nvim-tree/actions/dispatch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,51 @@ local M = {}

local Actions = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first instinct is was to move each of these to an dispatch.lua in each directory however that adds no value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess so :) i still want to improve this module since it's a bit clunky imo.

close = view.close,
close_node = require("nvim-tree.actions.movements").parent_node(true),
collapse_all = require("nvim-tree.actions.collapse-all").fn,
expand_all = require("nvim-tree.actions.expand-all").fn,
copy_absolute_path = require("nvim-tree.actions.copy-paste").copy_absolute_path,
copy_name = require("nvim-tree.actions.copy-paste").copy_filename,
copy_path = require("nvim-tree.actions.copy-paste").copy_path,
copy = require("nvim-tree.actions.copy-paste").copy,
create = require("nvim-tree.actions.create-file").fn,
cut = require("nvim-tree.actions.copy-paste").cut,
dir_up = require("nvim-tree.actions.dir-up").fn,
first_sibling = require("nvim-tree.actions.movements").sibling(-math.huge),
full_rename = require("nvim-tree.actions.rename-file").fn(true),
last_sibling = require("nvim-tree.actions.movements").sibling(math.huge),
next_diag_item = require("nvim-tree.actions.movements").find_item("next", "diag"),
next_git_item = require("nvim-tree.actions.movements").find_item("next", "git"),
next_sibling = require("nvim-tree.actions.movements").sibling(1),
parent_node = require("nvim-tree.actions.movements").parent_node(false),
paste = require("nvim-tree.actions.copy-paste").paste,
prev_diag_item = require("nvim-tree.actions.movements").find_item("prev", "diag"),
prev_git_item = require("nvim-tree.actions.movements").find_item("prev", "git"),
prev_sibling = require("nvim-tree.actions.movements").sibling(-1),
refresh = require("nvim-tree.actions.reloaders").reload_explorer,
remove = require("nvim-tree.actions.remove-file").fn,
rename = require("nvim-tree.actions.rename-file").fn(false),
run_file_command = require("nvim-tree.actions.run-command").run_file_command,
search_node = require("nvim-tree.actions.search-node").fn,
toggle_file_info = require("nvim-tree.actions.file-popup").toggle_file_info,
system_open = require("nvim-tree.actions.system-open").fn,
toggle_dotfiles = require("nvim-tree.actions.toggles").dotfiles,
toggle_custom = require("nvim-tree.actions.toggles").custom,
toggle_git_ignored = require("nvim-tree.actions.toggles").git_ignored,
trash = require("nvim-tree.actions.trash").fn,

-- Tree modifiers
collapse_all = require("nvim-tree.actions.tree-modifiers.collapse-all").fn,
expand_all = require("nvim-tree.actions.tree-modifiers.expand-all").fn,
toggle_dotfiles = require("nvim-tree.actions.tree-modifiers.toggles").dotfiles,
toggle_custom = require("nvim-tree.actions.tree-modifiers.toggles").custom,
toggle_git_ignored = require("nvim-tree.actions.tree-modifiers.toggles").git_ignored,

-- Filesystem operations
copy_absolute_path = require("nvim-tree.actions.fs.copy-paste").copy_absolute_path,
copy_name = require("nvim-tree.actions.fs.copy-paste").copy_filename,
copy_path = require("nvim-tree.actions.fs.copy-paste").copy_path,
copy = require("nvim-tree.actions.fs.copy-paste").copy,
create = require("nvim-tree.actions.fs.create-file").fn,
cut = require("nvim-tree.actions.fs.copy-paste").cut,
full_rename = require("nvim-tree.actions.fs.rename-file").fn(true),
paste = require("nvim-tree.actions.fs.copy-paste").paste,
trash = require("nvim-tree.actions.fs.trash").fn,
remove = require("nvim-tree.actions.fs.remove-file").fn,
rename = require("nvim-tree.actions.fs.rename-file").fn(false),

-- Movements in tree
close_node = require("nvim-tree.actions.moves.movements").parent_node(true),
first_sibling = require("nvim-tree.actions.moves.movements").sibling(-math.huge),
last_sibling = require("nvim-tree.actions.moves.movements").sibling(math.huge),
next_diag_item = require("nvim-tree.actions.moves.movements").find_item("next", "diag"),
next_git_item = require("nvim-tree.actions.moves.movements").find_item("next", "git"),
next_sibling = require("nvim-tree.actions.moves.movements").sibling(1),
parent_node = require("nvim-tree.actions.moves.movements").parent_node(false),
prev_diag_item = require("nvim-tree.actions.moves.movements").find_item("prev", "diag"),
prev_git_item = require("nvim-tree.actions.moves.movements").find_item("prev", "git"),
prev_sibling = require("nvim-tree.actions.moves.movements").sibling(-1),

-- Other types
refresh = require("nvim-tree.actions.reloaders.reloaders").reload_explorer,
dir_up = require("nvim-tree.actions.root.dir-up").fn,
search_node = require("nvim-tree.actions.finders.search-node").fn,
run_file_command = require("nvim-tree.actions.node.run-command").run_file_command,
toggle_file_info = require("nvim-tree.actions.node.file-popup").toggle_file_info,
system_open = require("nvim-tree.actions.node.system-open").fn,
}

local function handle_action_on_help_ui(action)
if action == "close" or action == "toggle_help" then
require("nvim-tree.actions.toggles").help()
require("nvim-tree.actions.tree-modifiers.toggles").help()
end
end

Expand All @@ -55,9 +63,9 @@ end

local function change_dir_action(node)
if node.name == ".." then
require("nvim-tree.actions.change-dir").fn ".."
require("nvim-tree.actions.root.change-dir").fn ".."
elseif node.nodes ~= nil then
require("nvim-tree.actions.change-dir").fn(lib.get_last_group_node(node).absolute_path)
require("nvim-tree.actions.root.change-dir").fn(lib.get_last_group_node(node).absolute_path)
end
end

Expand All @@ -66,7 +74,7 @@ local function open_file(action, node)
if node.link_to and not node.nodes then
path = node.link_to
end
require("nvim-tree.actions.open-file").fn(action, path)
require("nvim-tree.actions.node.open-file").fn(action, path)
end

local function handle_tree_actions(action)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
local api = vim.api
local uv = vim.loop

local utils = require "nvim-tree.utils"
local core = require "nvim-tree.core"
local filters = require "nvim-tree.explorer.filters"
local find_file = require("nvim-tree.actions.find-file").fn
local find_file = require("nvim-tree.actions.finders.find-file").fn

local M = {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ local function do_paste(node, action_type, action_fn)

clipboard[action_type] = {}
if M.enable_reload then
return require("nvim-tree.actions.reloaders").reload_explorer()
return require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function M.fn(node)
end
events._dispatch_folder_created(new_file_path)
if M.enable_reload then
require("nvim-tree.actions.reloaders").reload_explorer()
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
end
-- INFO: defer needed when reload is automatic (watchers)
vim.defer_fn(function()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function M.fn(node)
clear_buffer(node.absolute_path)
end
if M.enable_reload then
require("nvim-tree.actions.reloaders").reload_explorer()
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function M.fn(with_sub)
utils.rename_loaded_buffers(node.absolute_path, new_file_path)
events._dispatch_node_renamed(abs_path, new_file_path)
if M.enable_reload then
require("nvim-tree.actions.reloaders").reload_explorer()
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
end
end)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function M.fn(node)
end
events._dispatch_folder_removed(node.absolute_path)
if M.enable_reload then
require("nvim-tree.actions.reloaders").reload_explorer()
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
end
end)
else
Expand All @@ -100,7 +100,7 @@ function M.fn(node)
events._dispatch_file_removed(node.absolute_path)
clear_buffer(node.absolute_path)
if M.enable_reload then
require("nvim-tree.actions.reloaders").reload_explorer()
require("nvim-tree.actions.reloaders.reloaders").reload_explorer()
end
end)
end
Expand Down
18 changes: 9 additions & 9 deletions lua/nvim-tree/actions/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,15 @@ local DEFAULT_MAPPING_CONFIG = {
}

function M.setup(opts)
require("nvim-tree.actions.system-open").setup(opts)
require("nvim-tree.actions.trash").setup(opts)
require("nvim-tree.actions.open-file").setup(opts)
require("nvim-tree.actions.change-dir").setup(opts)
require("nvim-tree.actions.create-file").setup(opts)
require("nvim-tree.actions.rename-file").setup(opts)
require("nvim-tree.actions.remove-file").setup(opts)
require("nvim-tree.actions.copy-paste").setup(opts)
require("nvim-tree.actions.expand-all").setup(opts)
require("nvim-tree.actions.fs.trash").setup(opts)
require("nvim-tree.actions.node.system-open").setup(opts)
require("nvim-tree.actions.node.open-file").setup(opts)
require("nvim-tree.actions.root.change-dir").setup(opts)
require("nvim-tree.actions.fs.create-file").setup(opts)
require("nvim-tree.actions.fs.rename-file").setup(opts)
require("nvim-tree.actions.fs.remove-file").setup(opts)
require("nvim-tree.actions.fs.copy-paste").setup(opts)
require("nvim-tree.actions.tree-modifiers.expand-all").setup(opts)

cleanup_existing_mappings()
M.mappings = vim.deepcopy(DEFAULT_MAPPINGS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ local M = {}

function M.fn(node)
if not node or node.name == ".." then
return require("nvim-tree.actions.change-dir").fn ".."
return require("nvim-tree.actions.root.change-dir").fn ".."
else
local newdir = vim.fn.fnamemodify(utils.path_remove_trailing(core.get_cwd()), ":h")
require("nvim-tree.actions.change-dir").fn(newdir)
return require("nvim-tree.actions.find-file").fn(node.absolute_path)
require("nvim-tree.actions.root.change-dir").fn(newdir)
return require("nvim-tree.actions.finders.find-file").fn(node.absolute_path)
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local view = require "nvim-tree.view"
local filters = require "nvim-tree.explorer.filters"
local renderer = require "nvim-tree.renderer"
local reloaders = require "nvim-tree.actions.reloaders"
local reloaders = require "nvim-tree.actions.reloaders.reloaders"

local M = {}

Expand Down
26 changes: 13 additions & 13 deletions lua/nvim-tree/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ end

local function handle_buf_cwd(cwd)
if M.respect_buf_cwd and cwd ~= core.get_cwd() then
require("nvim-tree.actions.change-dir").fn(cwd)
require("nvim-tree.actions.root.change-dir").fn(cwd)
end
end

Expand Down Expand Up @@ -107,18 +107,18 @@ function M.open(cwd)
view.restore_tab_state()
end

-- @deprecated: use nvim-tree.actions.collapse-all.fn
M.collapse_all = require("nvim-tree.actions.collapse-all").fn
-- @deprecated: use nvim-tree.actions.dir-up.fn
M.dir_up = require("nvim-tree.actions.dir-up").fn
-- @deprecated: use nvim-tree.actions.change-dir.fn
M.change_dir = require("nvim-tree.actions.change-dir").fn
-- @deprecated: use nvim-tree.actions.reloaders.reload_explorer
M.refresh_tree = require("nvim-tree.actions.reloaders").reload_explorer
-- @deprecated: use nvim-tree.actions.reloaders.reload_git
M.reload_git = require("nvim-tree.actions.reloaders").reload_git
-- @deprecated: use nvim-tree.actions.find-file.fn
M.set_index_and_redraw = require("nvim-tree.actions.find-file").fn
-- @deprecated: use nvim-tree.actions.tree-modifiers.collapse-all.fn
M.collapse_all = require("nvim-tree.actions.tree-modifiers.collapse-all").fn
-- @deprecated: use nvim-tree.actions.root.dir-up.fn
M.dir_up = require("nvim-tree.actions.root.dir-up").fn
-- @deprecated: use nvim-tree.actions.root.change-dir.fn
M.change_dir = require("nvim-tree.actions.root.change-dir").fn
-- @deprecated: use nvim-tree.actions.reloaders.reloaders.reload_explorer
M.refresh_tree = require("nvim-tree.actions.reloaders.reloaders").reload_explorer
-- @deprecated: use nvim-tree.actions.reloaders.reloaders.reload_git
M.reload_git = require("nvim-tree.actions.reloaders.reloaders").reload_git
-- @deprecated: use nvim-tree.actions.finders.find-file.fn
M.set_index_and_redraw = require("nvim-tree.actions.finders.find-file").fn

function M.setup(opts)
M.hijack_unnamed_buffer_when_opening = opts.hijack_unnamed_buffer_when_opening
Expand Down
2 changes: 1 addition & 1 deletion lua/nvim-tree/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ function M._prevent_buffer_override()
M.open { focus_tree = false }
require("nvim-tree.renderer").draw()
pcall(a.nvim_win_close, curwin, { force = true })
require("nvim-tree.actions.open-file").fn("edit", bufname)
require("nvim-tree.actions.node.open-file").fn("edit", bufname)
end)
end

Expand Down