refacto: make git module interface to wait for job to finish

allows simplify the explore/reload/find/initialization by making the
whole code synchronous. No more callback needed.
This commit is contained in:
kiyan
2022-02-21 19:12:16 +01:00
parent a9fe57c0d8
commit f977e5c05a
7 changed files with 62 additions and 94 deletions

View File

@@ -102,9 +102,8 @@ function M.fn(node)
a.nvim_out_write(file..' was properly created\n')
end
events._dispatch_folder_created(file)
require'nvim-tree.actions.reloaders'.reload_explorer(function()
focus_file(file)
end)
require'nvim-tree.actions.reloaders'.reload_explorer()
focus_file(file)
end
return M

View File

@@ -1,7 +1,5 @@
local view = require'nvim-tree.view'
local utils = require'nvim-tree.utils'
local explorer_module = require"nvim-tree.explorer"
local git = require"nvim-tree.git"
local renderer = require"nvim-tree.renderer"
local M = {}
@@ -36,15 +34,7 @@ function M.fn(fname)
if not node.open then
node.open = true
tree_altered = true
end
if #node.nodes == 0 then
local git_finished = false
git.load_project_status(node.absolute_path, function(status)
explorer_module.explore(node, status)
git_finished = true
end)
while not vim.wait(10, function() return git_finished end, 10) do end
TreeExplorer:expand(node)
end
if iterate_nodes(node.nodes) ~= nil then

View File

@@ -33,23 +33,19 @@ function M.reload_node_status(parent_node, projects)
end
local event_running = false
function M.reload_explorer(callback)
function M.reload_explorer()
if event_running or not TreeExplorer or not TreeExplorer.cwd or vim.v.exiting ~= vim.NIL then
return
end
event_running = true
git.reload(function(projects)
refresh_nodes(TreeExplorer, projects)
if view.is_visible() then
renderer.draw()
if callback and type(callback) == 'function' then
callback()
end
end
diagnostics.update()
event_running = false
end)
local projects = git.reload()
refresh_nodes(TreeExplorer, projects)
if view.is_visible() then
renderer.draw()
end
diagnostics.update()
event_running = false
end
function M.reload_git()
@@ -58,11 +54,10 @@ function M.reload_git()
end
event_running = true
git.reload(function(projects)
M.reload_node_status(TreeExplorer, projects)
renderer.draw()
event_running = false
end)
local projects = git.reload()
M.reload_node_status(TreeExplorer, projects)
renderer.draw()
event_running = false
end
return M