feat/chore: rewrite git with job and some other fixes (#743)

* feat/chore: rewrite git with job and some other fixes

* fix: fs clear window, rename echo_warning -> warn

also fix renaming and add an event blocker to avoid running many events
at the same time
This commit is contained in:
Kiyan
2021-11-27 16:02:54 +01:00
committed by GitHub
parent b853e1083c
commit 6662b60a2b
15 changed files with 453 additions and 354 deletions

View File

@@ -0,0 +1,86 @@
local git_utils = require'nvim-tree.git.utils'
local Runner = require'nvim-tree.git.runner'
local M = {
config = nil,
projects = {},
cwd_to_project_root = {}
}
function M.reload(callback)
local num_projects = vim.tbl_count(M.projects)
if not M.config.enable or num_projects == 0 then
return callback({})
end
local done = 0
for project_root in pairs(M.projects) do
M.projects[project_root] = {}
Runner.run {
project_root = project_root,
list_untracked = git_utils.should_show_untracked(project_root),
list_ignored = M.config.ignore,
timeout = M.config.timeout,
on_end = function(git_status)
M.projects[project_root] = {
files = git_status,
dirs = git_utils.file_status_to_dir_status(git_status, project_root)
}
done = done + 1
if done == num_projects then
callback(M.projects)
end
end
}
end
end
function M.get_project_root(cwd)
if M.cwd_to_project_root[cwd] then
return M.cwd_to_project_root[cwd]
end
if M.cwd_to_project_root[cwd] == false then
return nil
end
local project_root = git_utils.get_toplevel(cwd)
return project_root
end
function M.load_project_status(cwd, callback)
if not M.config.enable then
return callback({})
end
local project_root = M.get_project_root(cwd)
if not project_root then
M.cwd_to_project_root[cwd] = false
return callback({})
end
local status = M.projects[project_root]
if status then
return callback(status)
end
Runner.run {
project_root = project_root,
list_untracked = git_utils.should_show_untracked(project_root),
list_ignored = M.config.ignore,
timeout = M.config.timeout,
on_end = function(git_status)
M.projects[project_root] = {
files = git_status,
dirs = git_utils.file_status_to_dir_status(git_status, project_root)
}
callback(M.projects[project_root])
end
}
end
function M.setup(opts)
M.config = opts.git
end
return M