diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index 7fa2b4b6204..fc4cb1144aa 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -205,7 +205,6 @@ 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 - log.line("dev", "BufWritePost reloading") reloaders.reload_explorer() end end, diff --git a/lua/nvim-tree/explorer/reload.lua b/lua/nvim-tree/explorer/reload.lua index 500b72b2b8d..f151447abe1 100644 --- a/lua/nvim-tree/explorer/reload.lua +++ b/lua/nvim-tree/explorer/reload.lua @@ -20,18 +20,12 @@ local function update_status(nodes_by_path, node_ignored, status) end end --- TODO always use callback once async/await is available local function reload_and_get_git_project(path, callback) local project_root = git.get_project_root(path) - if callback then - git.reload_project(project_root, path, function() - callback(project_root, git.get_project(project_root) or {}) - end) - else - git.reload_project(project_root, path) - return project_root, git.get_project(project_root) or {} - end + git.reload_project(project_root, path, function() + callback(project_root, git.get_project(project_root) or {}) + end) end local function update_parent_statuses(node, project, root) @@ -149,32 +143,21 @@ end ---Refresh contents and git status for a single node ---@param node table +---@param callback function function M.refresh_node(node, callback) if type(node) ~= "table" then - if callback then - callback() - end - return + callback() end local parent_node = utils.get_parent_of_group(node) - if callback then - reload_and_get_git_project(node.absolute_path, function(project_root, project) - require("nvim-tree.explorer.reload").reload(parent_node, project) - - update_parent_statuses(parent_node, project, project_root) - - callback() - end) - else - -- TODO use callback once async/await is available - local project_root, project = reload_and_get_git_project(node.absolute_path) - + reload_and_get_git_project(node.absolute_path, function(project_root, project) require("nvim-tree.explorer.reload").reload(parent_node, project) update_parent_statuses(parent_node, project, project_root) - end + + callback() + end) end function M.setup(opts) diff --git a/lua/nvim-tree/git/init.lua b/lua/nvim-tree/git/init.lua index 4a7277798b5..8c4117b4f56 100644 --- a/lua/nvim-tree/git/init.lua +++ b/lua/nvim-tree/git/init.lua @@ -37,6 +37,25 @@ local function reload_git_status(project_root, path, project, git_status) project.dirs = git_utils.file_status_to_dir_status(project.files, project_root) end +--- Is this path in a known ignored directory? +--- @param path string +--- @param project table git status +--- @return boolean +local function path_ignored_in_project(path, project) + if not path or not project then + return false + end + + if project and project.files then + for file, status in pairs(project.files) do + if status == "!!" and vim.startswith(path, file) then + return true + end + end + end + return false +end + function M.reload() if not M.config.git.enable then return {} @@ -58,7 +77,7 @@ function M.reload_project(project_root, path, callback) return end - if path and path:find(project_root, 1, true) ~= 1 then + if path and (path:find(project_root, 1, true) ~= 1 or path_ignored_in_project(path, project)) then if callback then callback() end @@ -107,6 +126,14 @@ function M.get_project_root(cwd) return nil end + -- short-circuit any known ignored paths + for root, project in pairs(M.projects) do + if project and path_ignored_in_project(cwd, project) then + M.cwd_to_project_root[cwd] = root + return root + end + end + local toplevel = git_utils.get_toplevel(cwd) for _, disabled_for_dir in ipairs(M.config.git.disable_for_dirs) do local toplevel_norm = vim.fn.fnamemodify(toplevel, ":p")