* 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:
Alexander Courtis
2023-04-03 16:20:52 +10:00
committed by GitHub
parent 7ad1c204c4
commit 0ef3d4613f
6 changed files with 173 additions and 73 deletions

View File

@@ -21,10 +21,18 @@ local function update_status(nodes_by_path, node_ignored, status)
end
end
local function reload_and_get_git_project(path)
-- 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)
git.reload_project(project_root, path)
return project_root, git.get_project(project_root) or {}
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
end
local function update_parent_statuses(node, project, root)
@@ -142,18 +150,32 @@ end
---Refresh contents and git status for a single node
---@param node table
function M.refresh_node(node)
function M.refresh_node(node, callback)
if type(node) ~= "table" then
if callback then
callback()
end
return
end
local parent_node = utils.get_parent_of_group(node)
local project_root, project = reload_and_get_git_project(node.absolute_path)
if callback then
reload_and_get_git_project(node.absolute_path, function(project_root, project)
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)
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)
update_parent_statuses(parent_node, project, project_root)
end
end
---Refresh contents and git status for all nodes to a path: actual directory and links

View File

@@ -59,8 +59,9 @@ function M.create_watcher(node)
else
log.line("watcher", "node event executing refresh '%s'", node.absolute_path)
end
require("nvim-tree.explorer.reload").refresh_node(node)
require("nvim-tree.renderer").draw()
require("nvim-tree.explorer.reload").refresh_node(node, function()
require("nvim-tree.renderer").draw()
end)
end)
end