diff --git a/lua/nvim-tree/actions/finders/find-file.lua b/lua/nvim-tree/actions/finders/find-file.lua index 8fec0cb5ea6..a99f4474552 100644 --- a/lua/nvim-tree/actions/finders/find-file.lua +++ b/lua/nvim-tree/actions/finders/find-file.lua @@ -3,6 +3,7 @@ local view = require "nvim-tree.view" local utils = require "nvim-tree.utils" local renderer = require "nvim-tree.renderer" local core = require "nvim-tree.core" +local reload = require "nvim-tree.explorer.reload" local Iterator = require "nvim-tree.iterators.node-iterator" local M = {} @@ -28,6 +29,8 @@ function M.fn(fname) local absolute_paths_searched = {} + reload.refresh_path(vim.fn.fnamemodify(fname, ":h")) + local found = Iterator.builder(core.get_explorer().nodes) :matcher(function(node) return node.absolute_path == fname_real or node.link_to == fname_real diff --git a/lua/nvim-tree/actions/fs/create-file.lua b/lua/nvim-tree/actions/fs/create-file.lua index f19e58041ef..aa43c643607 100644 --- a/lua/nvim-tree/actions/fs/create-file.lua +++ b/lua/nvim-tree/actions/fs/create-file.lua @@ -2,7 +2,7 @@ local utils = require "nvim-tree.utils" local events = require "nvim-tree.events" local lib = require "nvim-tree.lib" local core = require "nvim-tree.core" -local watch = require "nvim-tree.explorer.watch" +local reload = require "nvim-tree.explorer.reload" local notify = require "nvim-tree.notify" local M = {} @@ -111,7 +111,7 @@ function M.fn(node) -- synchronous call required so that we may focus the file now node = node.nodes ~= nil and node or node.parent if node then - watch.refresh_path(node.absolute_path) + reload.refresh_path(node.absolute_path) end end utils.focus_file(utils.path_remove_trailing(new_file_path)) diff --git a/lua/nvim-tree/explorer/reload.lua b/lua/nvim-tree/explorer/reload.lua index a7317461540..39f5b03e1bc 100644 --- a/lua/nvim-tree/explorer/reload.lua +++ b/lua/nvim-tree/explorer/reload.lua @@ -5,6 +5,7 @@ local filters = require "nvim-tree.explorer.filters" local sorters = require "nvim-tree.explorer.sorters" local live_filter = require "nvim-tree.live-filter" local notify = require "nvim-tree.notify" +local git = require "nvim-tree.git" local M = {} @@ -118,6 +119,33 @@ function M.reload(node, status) return node.nodes end +local function reload_and_get_git_project(path) + local project_root = git.get_project_root(path) + git.reload_project(project_root, path) + return project_root, git.get_project(project_root) or {} +end + +local function update_parent_statuses(node, project, root) + while project and node and node.absolute_path ~= root do + require("nvim-tree.explorer.common").update_git_status(node, false, project) + node = node.parent + end +end + +function M.refresh_path(path) + local n = utils.get_node_from_path(path) + if not n then + return + end + + local node = utils.get_parent_of_group(n) + local project_root, project = reload_and_get_git_project(path) + M.reload(node, project) + update_parent_statuses(node, project, project_root) + + require("nvim-tree.renderer").draw() +end + function M.setup(opts) M.config = opts.renderer end diff --git a/lua/nvim-tree/explorer/watch.lua b/lua/nvim-tree/explorer/watch.lua index 449b9a50e47..a909b4c06d0 100644 --- a/lua/nvim-tree/explorer/watch.lua +++ b/lua/nvim-tree/explorer/watch.lua @@ -1,23 +1,9 @@ local log = require "nvim-tree.log" local utils = require "nvim-tree.utils" -local git = require "nvim-tree.git" local Watcher = require("nvim-tree.watcher").Watcher local M = {} -local function reload_and_get_git_project(path) - local project_root = git.get_project_root(path) - git.reload_project(project_root, path) - return project_root, git.get_project(project_root) or {} -end - -local function update_parent_statuses(node, project, root) - while project and node and node.absolute_path ~= root do - require("nvim-tree.explorer.common").update_git_status(node, false, project) - node = node.parent - end -end - local function is_git(path) return vim.fn.fnamemodify(path, ":t") == ".git" end @@ -46,21 +32,6 @@ local function is_folder_ignored(path) return false end -function M.refresh_path(path) - log.line("watcher", "node event executing '%s'", path) - local n = utils.get_node_from_path(path) - if not n then - return - end - - local node = utils.get_parent_of_group(n) - local project_root, project = reload_and_get_git_project(path) - require("nvim-tree.explorer.reload").reload(node, project) - update_parent_statuses(node, project, project_root) - - require("nvim-tree.renderer").draw() -end - function M.create_watcher(absolute_path) if not M.enabled then return nil @@ -72,7 +43,8 @@ function M.create_watcher(absolute_path) local function callback(watcher) log.line("watcher", "node event scheduled %s", watcher.context) utils.debounce(watcher.context, M.debounce_delay, function() - M.refresh_path(watcher._path) + log.line("watcher", "node event executing '%s'", watcher._path) + require("nvim-tree.explorer.reload").refresh_path(watcher._path) end) end