chore: migrate to classic (#2991)
* add classic, migrating nodes classes
* add mixins to classic
* typechecked optargs constructors for nodes
* typechecked optargs constructors for watcher and event
* luacheck
* typechecked optargs constructors for GitRunner
* typechecked optargs constructors for Sorter
* typechecked optargs constructors for decorators, WIP
* typechecked optargs constructors for decorators, WIP
* typechecked optargs constructors for decorators
* remove class
* replace enums with named maps
* Renderer and Builder use classic, tidy opts
* LiveFilter uses classic, tidy opts
* Filter uses classic, tidy opts
* add FilterTypes named map
* move toggles into filters
* Marks uses classic, tidy opts
* Sorter uses classic, tidy opts
* Clipboard uses classic, tidy opts
* use supers for node methods
* HighlightDisplay uses classic
* protected :new
* Watcher tidy
* Revert "use supers for node methods"
This reverts commit 9fc7a866ec.
* Watcher tidy
* format
* format
* Filters private methods
* format
* Sorter type safety
* Sorter type safety
* Sorter type safety
* Sorter type safety
* Sorter type safety
* Sorter type safety
* tidy Runner
* tidy hi-test name
This commit is contained in:
committed by
GitHub
parent
610a1c189b
commit
3fc8de198c
@@ -128,25 +128,25 @@ function M.reload_project(toplevel, path, callback)
|
||||
return
|
||||
end
|
||||
|
||||
---@type GitRunnerOpts
|
||||
local runner_opts = {
|
||||
toplevel = toplevel,
|
||||
path = path,
|
||||
---@type GitRunnerArgs
|
||||
local args = {
|
||||
toplevel = toplevel,
|
||||
path = path,
|
||||
list_untracked = git_utils.should_show_untracked(toplevel),
|
||||
list_ignored = true,
|
||||
timeout = M.config.git.timeout,
|
||||
list_ignored = true,
|
||||
timeout = M.config.git.timeout,
|
||||
}
|
||||
|
||||
if callback then
|
||||
---@param path_xy GitPathXY
|
||||
runner_opts.callback = function(path_xy)
|
||||
args.callback = function(path_xy)
|
||||
reload_git_project(toplevel, path, project, path_xy)
|
||||
callback()
|
||||
end
|
||||
GitRunner:run(runner_opts)
|
||||
GitRunner:run(args)
|
||||
else
|
||||
-- TODO #1974 use callback once async/await is available
|
||||
reload_git_project(toplevel, path, project, GitRunner:run(runner_opts))
|
||||
reload_git_project(toplevel, path, project, GitRunner:run(args))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -276,10 +276,10 @@ function M.load_project(path)
|
||||
end
|
||||
|
||||
local path_xys = GitRunner:run({
|
||||
toplevel = toplevel,
|
||||
toplevel = toplevel,
|
||||
list_untracked = git_utils.should_show_untracked(toplevel),
|
||||
list_ignored = true,
|
||||
timeout = M.config.git.timeout,
|
||||
list_ignored = true,
|
||||
timeout = M.config.git.timeout,
|
||||
})
|
||||
|
||||
local watcher = nil
|
||||
@@ -298,15 +298,20 @@ function M.load_project(path)
|
||||
end
|
||||
|
||||
local git_dir = vim.env.GIT_DIR or M._git_dirs_by_toplevel[toplevel] or utils.path_join({ toplevel, ".git" })
|
||||
watcher = Watcher:create(git_dir, WATCHED_FILES, callback, {
|
||||
toplevel = toplevel,
|
||||
watcher = Watcher:create({
|
||||
path = git_dir,
|
||||
files = WATCHED_FILES,
|
||||
callback = callback,
|
||||
data = {
|
||||
toplevel = toplevel,
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
if path_xys then
|
||||
M._projects_by_toplevel[toplevel] = {
|
||||
files = path_xys,
|
||||
dirs = git_utils.project_files_to_project_dirs(path_xys, toplevel),
|
||||
files = path_xys,
|
||||
dirs = git_utils.project_files_to_project_dirs(path_xys, toplevel),
|
||||
watcher = watcher,
|
||||
}
|
||||
return M._projects_by_toplevel[toplevel]
|
||||
|
||||
@@ -2,9 +2,23 @@ local log = require("nvim-tree.log")
|
||||
local utils = require("nvim-tree.utils")
|
||||
local notify = require("nvim-tree.notify")
|
||||
|
||||
local Class = require("nvim-tree.class")
|
||||
local Class = require("nvim-tree.classic")
|
||||
|
||||
---@class (exact) GitRunnerOpts
|
||||
---@class (exact) GitRunner: Class
|
||||
---@field private toplevel string absolute path
|
||||
---@field private path string? absolute path
|
||||
---@field private list_untracked boolean
|
||||
---@field private list_ignored boolean
|
||||
---@field private timeout integer
|
||||
---@field private callback fun(path_xy: GitPathXY)?
|
||||
---@field private path_xy GitPathXY
|
||||
---@field private rc integer? -- -1 indicates timeout
|
||||
local GitRunner = Class:extend()
|
||||
|
||||
---@class GitRunner
|
||||
---@overload fun(args: GitRunnerArgs): GitRunner
|
||||
|
||||
---@class (exact) GitRunnerArgs
|
||||
---@field toplevel string absolute path
|
||||
---@field path string? absolute path
|
||||
---@field list_untracked boolean
|
||||
@@ -12,15 +26,23 @@ local Class = require("nvim-tree.class")
|
||||
---@field timeout integer
|
||||
---@field callback fun(path_xy: GitPathXY)?
|
||||
|
||||
---@class (exact) GitRunner: Class
|
||||
---@field private opts GitRunnerOpts
|
||||
---@field private path_xy GitPathXY
|
||||
---@field private rc integer? -- -1 indicates timeout
|
||||
local GitRunner = Class:new()
|
||||
|
||||
local timeouts = 0
|
||||
local MAX_TIMEOUTS = 5
|
||||
|
||||
---@protected
|
||||
---@param args GitRunnerArgs
|
||||
function GitRunner:new(args)
|
||||
self.toplevel = args.toplevel
|
||||
self.path = args.path
|
||||
self.list_untracked = args.list_untracked
|
||||
self.list_ignored = args.list_ignored
|
||||
self.timeout = args.timeout
|
||||
self.callback = args.callback
|
||||
|
||||
self.path_xy = {}
|
||||
self.rc = nil
|
||||
end
|
||||
|
||||
---@private
|
||||
---@param status string
|
||||
---@param path string|nil
|
||||
@@ -34,7 +56,7 @@ function GitRunner:parse_status_output(status, path)
|
||||
path = path:gsub("/", "\\")
|
||||
end
|
||||
if #status > 0 and #path > 0 then
|
||||
self.path_xy[utils.path_remove_trailing(utils.path_join({ self.opts.toplevel, path }))] = status
|
||||
self.path_xy[utils.path_remove_trailing(utils.path_join({ self.toplevel, path }))] = status
|
||||
end
|
||||
end
|
||||
|
||||
@@ -81,11 +103,11 @@ end
|
||||
---@param stderr_handle uv.uv_pipe_t
|
||||
---@return uv.spawn.options
|
||||
function GitRunner:get_spawn_options(stdout_handle, stderr_handle)
|
||||
local untracked = self.opts.list_untracked and "-u" or nil
|
||||
local ignored = (self.opts.list_untracked and self.opts.list_ignored) and "--ignored=matching" or "--ignored=no"
|
||||
local untracked = self.list_untracked and "-u" or nil
|
||||
local ignored = (self.list_untracked and self.list_ignored) and "--ignored=matching" or "--ignored=no"
|
||||
return {
|
||||
args = { "--no-optional-locks", "status", "--porcelain=v1", "-z", ignored, untracked, self.opts.path },
|
||||
cwd = self.opts.toplevel,
|
||||
args = { "--no-optional-locks", "status", "--porcelain=v1", "-z", ignored, untracked, self.path },
|
||||
cwd = self.toplevel,
|
||||
stdio = { nil, stdout_handle, stderr_handle },
|
||||
}
|
||||
end
|
||||
@@ -139,7 +161,7 @@ function GitRunner:run_git_job(callback)
|
||||
end
|
||||
|
||||
local spawn_options = self:get_spawn_options(stdout, stderr)
|
||||
log.line("git", "running job with timeout %dms", self.opts.timeout)
|
||||
log.line("git", "running job with timeout %dms", self.timeout)
|
||||
log.line("git", "git %s", table.concat(utils.array_remove_nils(spawn_options.args), " "))
|
||||
|
||||
handle, pid = vim.loop.spawn(
|
||||
@@ -151,7 +173,7 @@ function GitRunner:run_git_job(callback)
|
||||
)
|
||||
|
||||
timer:start(
|
||||
self.opts.timeout,
|
||||
self.timeout,
|
||||
0,
|
||||
vim.schedule_wrap(function()
|
||||
on_finish(-1)
|
||||
@@ -191,17 +213,17 @@ end
|
||||
---@private
|
||||
function GitRunner:finalise()
|
||||
if self.rc == -1 then
|
||||
log.line("git", "job timed out %s %s", self.opts.toplevel, self.opts.path)
|
||||
log.line("git", "job timed out %s %s", self.toplevel, self.path)
|
||||
timeouts = timeouts + 1
|
||||
if timeouts == MAX_TIMEOUTS then
|
||||
notify.warn(string.format("%d git jobs have timed out after git.timeout %dms, disabling git integration.", timeouts,
|
||||
self.opts.timeout))
|
||||
self.timeout))
|
||||
require("nvim-tree.git").disable_git_integration()
|
||||
end
|
||||
elseif self.rc ~= 0 then
|
||||
log.line("git", "job fail rc %d %s %s", self.rc, self.opts.toplevel, self.opts.path)
|
||||
log.line("git", "job fail rc %d %s %s", self.rc, self.toplevel, self.path)
|
||||
else
|
||||
log.line("git", "job success %s %s", self.opts.toplevel, self.opts.path)
|
||||
log.line("git", "job success %s %s", self.toplevel, self.path)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -209,17 +231,17 @@ end
|
||||
---@private
|
||||
---@return GitPathXY?
|
||||
function GitRunner:execute()
|
||||
local async = self.opts.callback ~= nil
|
||||
local profile = log.profile_start("git %s job %s %s", async and "async" or "sync", self.opts.toplevel, self.opts.path)
|
||||
local async = self.callback ~= nil
|
||||
local profile = log.profile_start("git %s job %s %s", async and "async" or "sync", self.toplevel, self.path)
|
||||
|
||||
if async and self.opts.callback then
|
||||
if async and self.callback then
|
||||
-- async, always call back
|
||||
self:run_git_job(function()
|
||||
log.profile_end(profile)
|
||||
|
||||
self:finalise()
|
||||
|
||||
self.opts.callback(self.path_xy)
|
||||
self.callback(self.path_xy)
|
||||
end)
|
||||
else
|
||||
-- sync, maybe call back
|
||||
@@ -230,8 +252,8 @@ function GitRunner:execute()
|
||||
|
||||
self:finalise()
|
||||
|
||||
if self.opts.callback then
|
||||
self.opts.callback(self.path_xy)
|
||||
if self.callback then
|
||||
self.callback(self.path_xy)
|
||||
else
|
||||
return self.path_xy
|
||||
end
|
||||
@@ -240,15 +262,10 @@ end
|
||||
|
||||
---Static method to run a git process, which will be killed if it takes more than timeout
|
||||
---Return nil when callback present
|
||||
---@param opts GitRunnerOpts
|
||||
---@param args GitRunnerArgs
|
||||
---@return GitPathXY?
|
||||
function GitRunner:run(opts)
|
||||
---@type GitRunner
|
||||
local runner = {
|
||||
opts = opts,
|
||||
path_xy = {},
|
||||
}
|
||||
runner = GitRunner:new(runner)
|
||||
function GitRunner:run(args)
|
||||
local runner = GitRunner(args)
|
||||
|
||||
return runner:execute()
|
||||
end
|
||||
|
||||
@@ -172,8 +172,8 @@ function M.git_status_dir(parent_ignored, project, path, path_fallback)
|
||||
elseif project then
|
||||
ns = {
|
||||
file = project.files and (project.files[path] or project.files[path_fallback]),
|
||||
dir = project.dirs and {
|
||||
direct = project.dirs.direct and project.dirs.direct[path],
|
||||
dir = project.dirs and {
|
||||
direct = project.dirs.direct and project.dirs.direct[path],
|
||||
indirect = project.dirs.indirect and project.dirs.indirect[path],
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user