feat(explorer): add filesystem watchers (#1304)
* feat(explorer): add experimental watchers This commit introduces watchers to update the tree. This behavior is introduced behind an "filesystem_watchers" option which should prevent instabilities. It will become the default at some point. Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
@@ -165,7 +165,9 @@ local function do_paste(node, action_type, action_fn)
|
||||
end
|
||||
|
||||
clipboard[action_type] = {}
|
||||
return require("nvim-tree.actions.reloaders").reload_explorer()
|
||||
if not M.enable_reload then
|
||||
return require("nvim-tree.actions.reloaders").reload_explorer()
|
||||
end
|
||||
end
|
||||
|
||||
local function do_cut(source, destination)
|
||||
@@ -242,6 +244,7 @@ end
|
||||
|
||||
function M.setup(opts)
|
||||
M.use_system_clipboard = opts.actions.use_system_clipboard
|
||||
M.enable_reload = not opts.filesystem_watchers.enable
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -42,7 +42,7 @@ local function get_num_nodes(iter)
|
||||
end
|
||||
|
||||
local function get_containing_folder(node)
|
||||
local is_open = M.config.create_in_closed_folder or node.open
|
||||
local is_open = M.create_in_closed_folder or node.open
|
||||
if node.nodes ~= nil and is_open then
|
||||
return utils.path_add_trailing(node.absolute_path)
|
||||
end
|
||||
@@ -107,13 +107,19 @@ function M.fn(node)
|
||||
a.nvim_out_write(new_file_path .. " was properly created\n")
|
||||
end
|
||||
events._dispatch_folder_created(new_file_path)
|
||||
require("nvim-tree.actions.reloaders").reload_explorer()
|
||||
focus_file(new_file_path)
|
||||
if M.enable_reload then
|
||||
require("nvim-tree.actions.reloaders").reload_explorer()
|
||||
end
|
||||
-- INFO: defer needed when reload is automatic (watchers)
|
||||
vim.defer_fn(function()
|
||||
focus_file(new_file_path)
|
||||
end, 50)
|
||||
end)
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.config = opts
|
||||
M.create_in_closed_folder = opts.create_in_closed_folder
|
||||
M.enable_reload = not opts.filesystem_watchers.enable
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -403,13 +403,14 @@ local DEFAULT_MAPPING_CONFIG = {
|
||||
}
|
||||
|
||||
function M.setup(opts)
|
||||
require("nvim-tree.actions.system-open").setup(opts.system_open)
|
||||
require("nvim-tree.actions.trash").setup(opts.trash)
|
||||
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.create-file").setup(opts)
|
||||
require("nvim-tree.actions.expand-all").setup(opts)
|
||||
|
||||
local user_map_config = (opts.view or {}).mappings or {}
|
||||
|
||||
@@ -86,11 +86,14 @@ function M.fn(node)
|
||||
events._dispatch_file_removed(node.absolute_path)
|
||||
clear_buffer(node.absolute_path)
|
||||
end
|
||||
require("nvim-tree.actions.reloaders").reload_explorer()
|
||||
if M.enable_reload then
|
||||
require("nvim-tree.actions.reloaders").reload_explorer()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.enable_reload = not opts.filesystem_watchers.enable
|
||||
M.close_window = opts.actions.remove_file.close_window
|
||||
end
|
||||
|
||||
|
||||
@@ -37,9 +37,15 @@ function M.fn(with_sub)
|
||||
a.nvim_out_write(node.absolute_path .. " ➜ " .. new_file_path .. "\n")
|
||||
utils.rename_loaded_buffers(node.absolute_path, new_file_path)
|
||||
events._dispatch_node_renamed(abs_path, new_file_path)
|
||||
require("nvim-tree.actions.reloaders").reload_explorer()
|
||||
if M.enable_reload then
|
||||
require("nvim-tree.actions.reloaders").reload_explorer()
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.enable_reload = not opts.filesystem_watchers.enable
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
@@ -51,7 +51,7 @@ function M.fn(node)
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.config.system_open = opts or {}
|
||||
M.config.system_open = opts.system_open or {}
|
||||
|
||||
if #M.config.system_open.cmd == 0 then
|
||||
if M.config.is_windows then
|
||||
|
||||
@@ -71,20 +71,25 @@ function M.fn(node)
|
||||
if node.nodes ~= nil and not node.link_to then
|
||||
trash_path(function()
|
||||
events._dispatch_folder_removed(node.absolute_path)
|
||||
require("nvim-tree.actions.reloaders").reload_explorer()
|
||||
if M.enable_reload then
|
||||
require("nvim-tree.actions.reloaders").reload_explorer()
|
||||
end
|
||||
end)
|
||||
else
|
||||
trash_path(function()
|
||||
events._dispatch_file_removed(node.absolute_path)
|
||||
clear_buffer(node.absolute_path)
|
||||
require("nvim-tree.actions.reloaders").reload_explorer()
|
||||
if M.enable_reload then
|
||||
require("nvim-tree.actions.reloaders").reload_explorer()
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function M.setup(opts)
|
||||
M.config.trash = opts or {}
|
||||
M.config.trash = opts.trash or {}
|
||||
M.enable_reload = not opts.filesystem_watchers.enable
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user