chore: resolve undefined-field
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
local log = require("nvim-tree.log")
|
local log = require("nvim-tree.log")
|
||||||
local utils = require("nvim-tree.utils")
|
local utils = require("nvim-tree.utils")
|
||||||
local git_utils = require("nvim-tree.git.utils")
|
local git_utils = require("nvim-tree.git.utils")
|
||||||
local runner = require("nvim-tree.git.runner")
|
|
||||||
|
local GitRunner = require("nvim-tree.git.runner")
|
||||||
local Watcher = require("nvim-tree.watcher").Watcher
|
local Watcher = require("nvim-tree.watcher").Watcher
|
||||||
local Iterator = require("nvim-tree.iterators.node-iterator")
|
local Iterator = require("nvim-tree.iterators.node-iterator")
|
||||||
local DirectoryNode = nil -- circular dependency
|
local DirectoryNode = nil -- circular dependency
|
||||||
@@ -36,7 +37,7 @@ local WATCHED_FILES = {
|
|||||||
---@param toplevel string|nil
|
---@param toplevel string|nil
|
||||||
---@param path string|nil
|
---@param path string|nil
|
||||||
---@param project table
|
---@param project table
|
||||||
---@param statuses GitStatusesXYByPath?
|
---@param statuses GitXYByPath?
|
||||||
local function reload_git_statuses(toplevel, path, project, statuses)
|
local function reload_git_statuses(toplevel, path, project, statuses)
|
||||||
if path then
|
if path then
|
||||||
for p in pairs(project.files) do
|
for p in pairs(project.files) do
|
||||||
@@ -105,7 +106,7 @@ function M.reload_project(toplevel, path, callback)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
---@type RunnerOpts
|
---@type GitRunnerOpts
|
||||||
local runner_opts = {
|
local runner_opts = {
|
||||||
toplevel = toplevel,
|
toplevel = toplevel,
|
||||||
path = path,
|
path = path,
|
||||||
@@ -115,15 +116,15 @@ function M.reload_project(toplevel, path, callback)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if callback then
|
if callback then
|
||||||
---@param statuses GitStatusesXYByPath
|
---@param statuses GitXYByPath
|
||||||
runner_opts.callback = function(statuses)
|
runner_opts.callback = function(statuses)
|
||||||
reload_git_statuses(toplevel, path, project, statuses)
|
reload_git_statuses(toplevel, path, project, statuses)
|
||||||
callback()
|
callback()
|
||||||
end
|
end
|
||||||
runner(runner_opts)
|
GitRunner:run(runner_opts)
|
||||||
else
|
else
|
||||||
-- TODO #1974 use callback once async/await is available
|
-- TODO #1974 use callback once async/await is available
|
||||||
reload_git_statuses(toplevel, path, project, runner(runner_opts))
|
reload_git_statuses(toplevel, path, project, GitRunner:run(runner_opts))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -203,16 +204,16 @@ local function reload_tree_at(toplevel)
|
|||||||
end
|
end
|
||||||
|
|
||||||
log.line("watcher", "git event executing '%s'", toplevel)
|
log.line("watcher", "git event executing '%s'", toplevel)
|
||||||
local root_node = utils.get_node_from_path(toplevel)
|
local base = utils.get_node_from_path(toplevel)
|
||||||
root_node = root_node and root_node:as(DirectoryNode)
|
base = base and base:as(DirectoryNode)
|
||||||
if not root_node then
|
if not base then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
M.reload_project(toplevel, nil, function()
|
M.reload_project(toplevel, nil, function()
|
||||||
local git_status = M.get_project(toplevel)
|
local git_status = M.get_project(toplevel)
|
||||||
|
|
||||||
Iterator.builder(root_node.nodes)
|
Iterator.builder(base.nodes)
|
||||||
:hidden()
|
:hidden()
|
||||||
:applier(function(node)
|
:applier(function(node)
|
||||||
local parent_ignored = node.parent and node.parent:is_git_ignored() or false
|
local parent_ignored = node.parent and node.parent:is_git_ignored() or false
|
||||||
@@ -224,7 +225,7 @@ local function reload_tree_at(toplevel)
|
|||||||
end)
|
end)
|
||||||
:iterate()
|
:iterate()
|
||||||
|
|
||||||
root_node.explorer.renderer:draw()
|
base.explorer.renderer:draw()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -248,7 +249,7 @@ function M.load_project_status(path)
|
|||||||
return status
|
return status
|
||||||
end
|
end
|
||||||
|
|
||||||
local statuses = runner({
|
local statuses = GitRunner:run({
|
||||||
toplevel = toplevel,
|
toplevel = toplevel,
|
||||||
list_untracked = git_utils.should_show_untracked(toplevel),
|
list_untracked = git_utils.should_show_untracked(toplevel),
|
||||||
list_ignored = true,
|
list_ignored = true,
|
||||||
|
|||||||
@@ -4,21 +4,21 @@ local notify = require("nvim-tree.notify")
|
|||||||
|
|
||||||
local Class = require("nvim-tree.class")
|
local Class = require("nvim-tree.class")
|
||||||
|
|
||||||
---@alias GitStatusesXYByPath table<string, string>
|
---@alias GitXYByPath table<string, string> -- short-format statuses
|
||||||
|
|
||||||
---@class (exact) RunnerOpts
|
---@class (exact) GitRunnerOpts
|
||||||
---@field toplevel string absolute path
|
---@field toplevel string absolute path
|
||||||
---@field path string? absolute path
|
---@field path string? absolute path
|
||||||
---@field list_untracked boolean
|
---@field list_untracked boolean
|
||||||
---@field list_ignored boolean
|
---@field list_ignored boolean
|
||||||
---@field timeout integer
|
---@field timeout integer
|
||||||
---@field callback fun(statuses: GitStatusesXYByPath)?
|
---@field callback fun(statuses: GitXYByPath)?
|
||||||
|
|
||||||
---@class (exact) Runner: Class
|
---@class (exact) GitRunner: Class
|
||||||
---@field opts RunnerOpts
|
---@field private opts GitRunnerOpts
|
||||||
---@field statuses GitStatusesXYByPath
|
---@field private statuses GitXYByPath
|
||||||
---@field rc integer? -- -1 indicates timeout
|
---@field private rc integer? -- -1 indicates timeout
|
||||||
local Runner = Class:new()
|
local GitRunner = Class:new()
|
||||||
|
|
||||||
local timeouts = 0
|
local timeouts = 0
|
||||||
local MAX_TIMEOUTS = 5
|
local MAX_TIMEOUTS = 5
|
||||||
@@ -26,7 +26,7 @@ local MAX_TIMEOUTS = 5
|
|||||||
---@private
|
---@private
|
||||||
---@param status string
|
---@param status string
|
||||||
---@param path string|nil
|
---@param path string|nil
|
||||||
function Runner:parse_status_output(status, path)
|
function GitRunner:parse_status_output(status, path)
|
||||||
if not path then
|
if not path then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -44,7 +44,7 @@ end
|
|||||||
---@param prev_output string
|
---@param prev_output string
|
||||||
---@param incoming string
|
---@param incoming string
|
||||||
---@return string
|
---@return string
|
||||||
function Runner:handle_incoming_data(prev_output, incoming)
|
function GitRunner:handle_incoming_data(prev_output, incoming)
|
||||||
if incoming and utils.str_find(incoming, "\n") then
|
if incoming and utils.str_find(incoming, "\n") then
|
||||||
local prev = prev_output .. incoming
|
local prev = prev_output .. incoming
|
||||||
local i = 1
|
local i = 1
|
||||||
@@ -82,7 +82,7 @@ end
|
|||||||
---@param stdout_handle uv.uv_pipe_t
|
---@param stdout_handle uv.uv_pipe_t
|
||||||
---@param stderr_handle uv.uv_pipe_t
|
---@param stderr_handle uv.uv_pipe_t
|
||||||
---@return uv.spawn.options
|
---@return uv.spawn.options
|
||||||
function Runner:get_spawn_options(stdout_handle, stderr_handle)
|
function GitRunner:get_spawn_options(stdout_handle, stderr_handle)
|
||||||
local untracked = self.opts.list_untracked and "-u" or nil
|
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 ignored = (self.opts.list_untracked and self.opts.list_ignored) and "--ignored=matching" or "--ignored=no"
|
||||||
return {
|
return {
|
||||||
@@ -94,7 +94,7 @@ end
|
|||||||
|
|
||||||
---@private
|
---@private
|
||||||
---@param output string
|
---@param output string
|
||||||
function Runner:log_raw_output(output)
|
function GitRunner:log_raw_output(output)
|
||||||
if log.enabled("git") and output and type(output) == "string" then
|
if log.enabled("git") and output and type(output) == "string" then
|
||||||
log.raw("git", "%s", output)
|
log.raw("git", "%s", output)
|
||||||
log.line("git", "done")
|
log.line("git", "done")
|
||||||
@@ -103,7 +103,7 @@ end
|
|||||||
|
|
||||||
---@private
|
---@private
|
||||||
---@param callback function|nil
|
---@param callback function|nil
|
||||||
function Runner:run_git_job(callback)
|
function GitRunner:run_git_job(callback)
|
||||||
local handle, pid
|
local handle, pid
|
||||||
local stdout = vim.loop.new_pipe(false)
|
local stdout = vim.loop.new_pipe(false)
|
||||||
local stderr = vim.loop.new_pipe(false)
|
local stderr = vim.loop.new_pipe(false)
|
||||||
@@ -181,7 +181,7 @@ function Runner:run_git_job(callback)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
function Runner:wait()
|
function GitRunner:wait()
|
||||||
local function is_done()
|
local function is_done()
|
||||||
return self.rc ~= nil
|
return self.rc ~= nil
|
||||||
end
|
end
|
||||||
@@ -191,7 +191,7 @@ function Runner:wait()
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@private
|
---@private
|
||||||
function Runner:finalise()
|
function GitRunner:finalise()
|
||||||
if self.rc == -1 then
|
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.opts.toplevel, self.opts.path)
|
||||||
timeouts = timeouts + 1
|
timeouts = timeouts + 1
|
||||||
@@ -207,8 +207,8 @@ function Runner:finalise()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@return GitStatusesXYByPath? statuses nil if callback present
|
---@return GitXYByPath? statuses nil if callback present
|
||||||
function Runner:run()
|
function GitRunner:execute()
|
||||||
local async = self.opts.callback ~= nil
|
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 profile = log.profile_start("git %s job %s %s", async and "async" or "sync", self.opts.toplevel, self.opts.path)
|
||||||
|
|
||||||
@@ -238,16 +238,18 @@ function Runner:run()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---Runs a git process, which will be killed if it takes more than timeout which defaults to 400ms
|
---Static method to run a git process, which will be killed if it takes more than timeout
|
||||||
---@param opts RunnerOpts
|
---@param opts GitRunnerOpts
|
||||||
---@return GitStatusesXYByPath? statuses nil if callback present
|
---@return GitXYByPath? statuses nil if callback present
|
||||||
return function(opts)
|
function GitRunner:run(opts)
|
||||||
---@type Runner
|
---@type GitRunner
|
||||||
local runner = {
|
local runner = {
|
||||||
opts = opts,
|
opts = opts,
|
||||||
statuses = {},
|
statuses = {},
|
||||||
}
|
}
|
||||||
runner = Runner:new(runner) --[[@as Runner]]
|
runner = GitRunner:new(runner) --[[@as GitRunner]]
|
||||||
|
|
||||||
return runner:run()
|
return runner:execute()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return GitRunner
|
||||||
|
|||||||
Reference in New Issue
Block a user