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

@@ -1,7 +1,6 @@
local uv = vim.loop
local git = require"nvim-tree.git"
local renderer = require"nvim-tree.renderer"
local M = {}
@@ -13,33 +12,24 @@ Explorer.__index = Explorer
function Explorer.new(cwd)
cwd = uv.fs_realpath(cwd or uv.cwd())
return setmetatable({
local explorer = setmetatable({
cwd = cwd,
nodes = {}
}, Explorer)
explorer:_load(explorer)
return explorer
end
function Explorer:_load(node)
local cwd = node.cwd or node.link_to or node.absolute_path
git.load_project_status(cwd, function(git_statuses)
M.explore(node, git_statuses)
if type(self.init_cb) == "function" then
self.init_cb(self)
self.init_cb = nil
end
end)
local git_statuses = git.load_project_status(cwd)
M.explore(node, git_statuses)
end
function Explorer:expand(node)
self.init_cb = renderer.draw
self:_load(node)
end
function Explorer:init(f)
self.init_cb = f
self:_load(self)
end
function M.setup(opts)
require"nvim-tree.explorer.utils".setup(opts)
end