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 <alex@courtis.org>
This commit is contained in:
Azad
2023-12-31 05:52:27 +01:00
committed by GitHub
parent dc839a72a6
commit f779abaf2a
20 changed files with 210 additions and 147 deletions

View File

@@ -5,14 +5,12 @@ local renderer = require "nvim-tree.renderer"
local view = require "nvim-tree.view"
local commands = require "nvim-tree.commands"
local utils = require "nvim-tree.utils"
local change_dir = require "nvim-tree.actions.root.change-dir"
local actions = require "nvim-tree.actions"
local legacy = require "nvim-tree.legacy"
local core = require "nvim-tree.core"
local reloaders = require "nvim-tree.actions.reloaders.reloaders"
local git = require "nvim-tree.git"
local filters = require "nvim-tree.explorer.filters"
local modified = require "nvim-tree.modified"
local find_file = require "nvim-tree.actions.tree.find-file"
local events = require "nvim-tree.events"
local notify = require "nvim-tree.notify"
@@ -51,7 +49,7 @@ function M.change_root(path, bufnr)
-- test if in vim_cwd
if utils.path_relative(path, vim_cwd) ~= path then
if vim_cwd ~= cwd then
change_dir.fn(vim_cwd)
actions.root.change_dir.fn(vim_cwd)
end
return
end
@@ -62,19 +60,19 @@ function M.change_root(path, bufnr)
-- otherwise test M.init_root
if _config.prefer_startup_root and utils.path_relative(path, M.init_root) ~= path then
change_dir.fn(M.init_root)
actions.root.change_dir.fn(M.init_root)
return
end
-- otherwise root_dirs
for _, dir in pairs(_config.root_dirs) do
dir = vim.fn.fnamemodify(dir, ":p")
if utils.path_relative(path, dir) ~= path then
change_dir.fn(dir)
actions.root.change_dir.fn(dir)
return
end
end
-- finally fall back to the folder containing the file
change_dir.fn(vim.fn.fnamemodify(path, ":p:h"))
actions.root.change_dir.fn(vim.fn.fnamemodify(path, ":p:h"))
end
function M.tab_enter()
@@ -87,7 +85,7 @@ function M.tab_enter()
end
end
view.open { focus_tree = false }
require("nvim-tree.renderer").draw()
renderer.draw()
end
end
@@ -103,7 +101,7 @@ function M.open_on_directory()
return
end
change_dir.force_dirchange(bufname, true)
actions.root.change_dir.force_dirchange(bufname, true)
end
function M.reset_highlight()
@@ -154,11 +152,11 @@ end
---@param name string|nil
function M.change_dir(name)
if name then
change_dir.fn(name)
actions.root.change_dir.fn(name)
end
if _config.update_focused_file.enable then
find_file.fn()
actions.tree.find_file.fn()
end
end
@@ -191,7 +189,7 @@ local function setup_autocommands(opts)
create_nvim_tree_autocmd("BufWritePost", {
callback = function()
if opts.auto_reload_on_write and not opts.filesystem_watchers.enable then
reloaders.reload_explorer()
actions.reloaders.reload_explorer()
end
end,
})
@@ -201,7 +199,7 @@ local function setup_autocommands(opts)
-- update opened file buffers
if (filters.config.filter_no_buffer or renderer.config.highlight_opened_files ~= "none") and vim.bo[data.buf].buftype == "" then
utils.debounce("Buf:filter_buffer", opts.view.debounce_delay, function()
reloaders.reload_explorer()
actions.reloaders.reload_explorer()
end)
end
end,
@@ -212,7 +210,7 @@ local function setup_autocommands(opts)
-- update opened file buffers
if (filters.config.filter_no_buffer or renderer.config.highlight_opened_files ~= "none") and vim.bo[data.buf].buftype == "" then
utils.debounce("Buf:filter_buffer", opts.view.debounce_delay, function()
reloaders.reload_explorer(nil, data.buf)
actions.reloaders.reload_explorer(nil, data.buf)
end)
end
end,
@@ -222,7 +220,7 @@ local function setup_autocommands(opts)
pattern = { "FugitiveChanged", "NeogitStatusRefreshed" },
callback = function()
if not opts.filesystem_watchers.enable and opts.git.enable then
reloaders.reload_git()
actions.reloaders.reload_git()
end
end,
})
@@ -251,7 +249,7 @@ local function setup_autocommands(opts)
create_nvim_tree_autocmd("BufEnter", {
callback = function()
utils.debounce("BufEnter:find_file", opts.view.debounce_delay, function()
find_file.fn()
actions.tree.find_file.fn()
end)
end,
})
@@ -266,7 +264,7 @@ local function setup_autocommands(opts)
callback = function()
if utils.is_nvim_tree_buf(0) then
if vim.fn.getcwd() ~= core.get_cwd() or (opts.reload_on_bufenter and not opts.filesystem_watchers.enable) then
reloaders.reload_explorer()
actions.reloaders.reload_explorer()
end
end
end,
@@ -317,7 +315,7 @@ local function setup_autocommands(opts)
callback = function()
utils.debounce("Buf:modified", opts.view.debounce_delay, function()
modified.reload()
reloaders.reload_explorer()
actions.reloaders.reload_explorer()
end)
end,
})