feat(#1974): experimental.git.async see https://github.com/nvim-tree/nvim-tree.lua/issues/2104 (#2094)
* async git watcher reload; callback hell for now * async git watcher reload; revert unnecessary extractions * async git watcher reload; callback and non-callback functions are required for sync codepaths that loop * async git watcher reload * async git watcher reload * feat(#1974): experimental.git.async * feat(#1974): experimental.git.async
This commit is contained in:
committed by
GitHub
parent
7ad1c204c4
commit
0ef3d4613f
@@ -22,36 +22,7 @@ local WATCHED_FILES = {
|
||||
"index", -- staging area
|
||||
}
|
||||
|
||||
function M.reload()
|
||||
if not M.config.git.enable then
|
||||
return {}
|
||||
end
|
||||
|
||||
for project_root in pairs(M.projects) do
|
||||
M.reload_project(project_root)
|
||||
end
|
||||
|
||||
return M.projects
|
||||
end
|
||||
|
||||
function M.reload_project(project_root, path)
|
||||
local project = M.projects[project_root]
|
||||
if not project or not M.config.git.enable then
|
||||
return
|
||||
end
|
||||
|
||||
if path and path:find(project_root, 1, true) ~= 1 then
|
||||
return
|
||||
end
|
||||
|
||||
local git_status = Runner.run {
|
||||
project_root = project_root,
|
||||
path = path,
|
||||
list_untracked = git_utils.should_show_untracked(project_root),
|
||||
list_ignored = true,
|
||||
timeout = M.config.git.timeout,
|
||||
}
|
||||
|
||||
local function reload_git_status(project_root, path, project, git_status)
|
||||
if path then
|
||||
for p in pairs(project.files) do
|
||||
if p:find(path, 1, true) == 1 then
|
||||
@@ -66,6 +37,54 @@ function M.reload_project(project_root, path)
|
||||
project.dirs = git_utils.file_status_to_dir_status(project.files, project_root)
|
||||
end
|
||||
|
||||
function M.reload()
|
||||
if not M.config.git.enable then
|
||||
return {}
|
||||
end
|
||||
|
||||
for project_root in pairs(M.projects) do
|
||||
M.reload_project(project_root)
|
||||
end
|
||||
|
||||
return M.projects
|
||||
end
|
||||
|
||||
function M.reload_project(project_root, path, callback)
|
||||
local project = M.projects[project_root]
|
||||
if not project or not M.config.git.enable then
|
||||
if callback then
|
||||
callback()
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if path and path:find(project_root, 1, true) ~= 1 then
|
||||
if callback then
|
||||
callback()
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
local opts = {
|
||||
project_root = project_root,
|
||||
path = path,
|
||||
list_untracked = git_utils.should_show_untracked(project_root),
|
||||
list_ignored = true,
|
||||
timeout = M.config.git.timeout,
|
||||
}
|
||||
|
||||
if callback then
|
||||
Runner.run(opts, function(git_status)
|
||||
reload_git_status(project_root, path, project, git_status)
|
||||
callback()
|
||||
end)
|
||||
else
|
||||
-- TODO use callback once async/await is available
|
||||
local git_status = Runner.run(opts)
|
||||
reload_git_status(project_root, path, project, git_status)
|
||||
end
|
||||
end
|
||||
|
||||
function M.get_project(project_root)
|
||||
return M.projects[project_root]
|
||||
end
|
||||
@@ -103,21 +122,22 @@ local function reload_tree_at(project_root)
|
||||
return
|
||||
end
|
||||
|
||||
M.reload_project(project_root)
|
||||
local git_status = M.get_project(project_root)
|
||||
M.reload_project(project_root, nil, function()
|
||||
local git_status = M.get_project(project_root)
|
||||
|
||||
Iterator.builder(root_node.nodes)
|
||||
:hidden()
|
||||
:applier(function(node)
|
||||
local parent_ignored = explorer_node.is_git_ignored(node.parent)
|
||||
explorer_node.update_git_status(node, parent_ignored, git_status)
|
||||
end)
|
||||
:recursor(function(node)
|
||||
return node.nodes and #node.nodes > 0 and node.nodes
|
||||
end)
|
||||
:iterate()
|
||||
Iterator.builder(root_node.nodes)
|
||||
:hidden()
|
||||
:applier(function(node)
|
||||
local parent_ignored = explorer_node.is_git_ignored(node.parent)
|
||||
explorer_node.update_git_status(node, parent_ignored, git_status)
|
||||
end)
|
||||
:recursor(function(node)
|
||||
return node.nodes and #node.nodes > 0 and node.nodes
|
||||
end)
|
||||
:iterate()
|
||||
|
||||
require("nvim-tree.renderer").draw()
|
||||
require("nvim-tree.renderer").draw()
|
||||
end)
|
||||
end
|
||||
|
||||
function M.load_project_status(cwd)
|
||||
|
||||
Reference in New Issue
Block a user