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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user