* fix(#1931): do not execute git status in git ignored directories * fix(#1931): reload.refresh_node is always asynchronous
This commit is contained in:
committed by
GitHub
parent
3b62c6bf2c
commit
273c1700eb
@@ -205,7 +205,6 @@ local function setup_autocommands(opts)
|
|||||||
create_nvim_tree_autocmd("BufWritePost", {
|
create_nvim_tree_autocmd("BufWritePost", {
|
||||||
callback = function()
|
callback = function()
|
||||||
if opts.auto_reload_on_write and not opts.filesystem_watchers.enable then
|
if opts.auto_reload_on_write and not opts.filesystem_watchers.enable then
|
||||||
log.line("dev", "BufWritePost reloading")
|
|
||||||
reloaders.reload_explorer()
|
reloaders.reload_explorer()
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|||||||
@@ -20,18 +20,12 @@ local function update_status(nodes_by_path, node_ignored, status)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- TODO always use callback once async/await is available
|
|
||||||
local function reload_and_get_git_project(path, callback)
|
local function reload_and_get_git_project(path, callback)
|
||||||
local project_root = git.get_project_root(path)
|
local project_root = git.get_project_root(path)
|
||||||
|
|
||||||
if callback then
|
git.reload_project(project_root, path, function()
|
||||||
git.reload_project(project_root, path, function()
|
callback(project_root, git.get_project(project_root) or {})
|
||||||
callback(project_root, git.get_project(project_root) or {})
|
end)
|
||||||
end)
|
|
||||||
else
|
|
||||||
git.reload_project(project_root, path)
|
|
||||||
return project_root, git.get_project(project_root) or {}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update_parent_statuses(node, project, root)
|
local function update_parent_statuses(node, project, root)
|
||||||
@@ -149,32 +143,21 @@ end
|
|||||||
|
|
||||||
---Refresh contents and git status for a single node
|
---Refresh contents and git status for a single node
|
||||||
---@param node table
|
---@param node table
|
||||||
|
---@param callback function
|
||||||
function M.refresh_node(node, callback)
|
function M.refresh_node(node, callback)
|
||||||
if type(node) ~= "table" then
|
if type(node) ~= "table" then
|
||||||
if callback then
|
callback()
|
||||||
callback()
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local parent_node = utils.get_parent_of_group(node)
|
local parent_node = utils.get_parent_of_group(node)
|
||||||
|
|
||||||
if callback then
|
reload_and_get_git_project(node.absolute_path, function(project_root, project)
|
||||||
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)
|
|
||||||
|
|
||||||
require("nvim-tree.explorer.reload").reload(parent_node, project)
|
require("nvim-tree.explorer.reload").reload(parent_node, project)
|
||||||
|
|
||||||
update_parent_statuses(parent_node, project, project_root)
|
update_parent_statuses(parent_node, project, project_root)
|
||||||
end
|
|
||||||
|
callback()
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.setup(opts)
|
function M.setup(opts)
|
||||||
|
|||||||
@@ -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)
|
project.dirs = git_utils.file_status_to_dir_status(project.files, project_root)
|
||||||
end
|
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()
|
function M.reload()
|
||||||
if not M.config.git.enable then
|
if not M.config.git.enable then
|
||||||
return {}
|
return {}
|
||||||
@@ -58,7 +77,7 @@ function M.reload_project(project_root, path, callback)
|
|||||||
return
|
return
|
||||||
end
|
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
|
if callback then
|
||||||
callback()
|
callback()
|
||||||
end
|
end
|
||||||
@@ -107,6 +126,14 @@ function M.get_project_root(cwd)
|
|||||||
return nil
|
return nil
|
||||||
end
|
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)
|
local toplevel = git_utils.get_toplevel(cwd)
|
||||||
for _, disabled_for_dir in ipairs(M.config.git.disable_for_dirs) do
|
for _, disabled_for_dir in ipairs(M.config.git.disable_for_dirs) do
|
||||||
local toplevel_norm = vim.fn.fnamemodify(toplevel, ":p")
|
local toplevel_norm = vim.fn.fnamemodify(toplevel, ":p")
|
||||||
|
|||||||
Reference in New Issue
Block a user