Skip to content

Commit 1c812ae

Browse files
committed
chore: resolve undefined-field
1 parent ab4f769 commit 1c812ae

File tree

2 files changed

+39
-36
lines changed

2 files changed

+39
-36
lines changed

lua/nvim-tree/git/init.lua

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
local log = require("nvim-tree.log")
22
local utils = require("nvim-tree.utils")
33
local git_utils = require("nvim-tree.git.utils")
4-
local runner = require("nvim-tree.git.runner")
4+
5+
local GitRunner = require("nvim-tree.git.runner")
56
local Watcher = require("nvim-tree.watcher").Watcher
67
local Iterator = require("nvim-tree.iterators.node-iterator")
78
local DirectoryNode = nil -- circular dependency
@@ -36,7 +37,7 @@ local WATCHED_FILES = {
3637
---@param toplevel string|nil
3738
---@param path string|nil
3839
---@param project table
39-
---@param statuses GitStatusesXYByPath?
40+
---@param statuses GitXYByPath?
4041
local function reload_git_statuses(toplevel, path, project, statuses)
4142
if path then
4243
for p in pairs(project.files) do
@@ -105,7 +106,7 @@ function M.reload_project(toplevel, path, callback)
105106
return
106107
end
107108

108-
---@type RunnerOpts
109+
---@type GitRunnerOpts
109110
local runner_opts = {
110111
toplevel = toplevel,
111112
path = path,
@@ -115,15 +116,15 @@ function M.reload_project(toplevel, path, callback)
115116
}
116117

117118
if callback then
118-
---@param statuses GitStatusesXYByPath
119+
---@param statuses GitXYByPath
119120
runner_opts.callback = function(statuses)
120121
reload_git_statuses(toplevel, path, project, statuses)
121122
callback()
122123
end
123-
runner(runner_opts)
124+
GitRunner:run(runner_opts)
124125
else
125126
-- TODO #1974 use callback once async/await is available
126-
reload_git_statuses(toplevel, path, project, runner(runner_opts))
127+
reload_git_statuses(toplevel, path, project, GitRunner:run(runner_opts))
127128
end
128129
end
129130

@@ -203,16 +204,16 @@ local function reload_tree_at(toplevel)
203204
end
204205

205206
log.line("watcher", "git event executing '%s'", toplevel)
206-
local root_node = utils.get_node_from_path(toplevel)
207-
root_node = root_node and root_node:as(DirectoryNode)
208-
if not root_node then
207+
local base = utils.get_node_from_path(toplevel)
208+
base = base and base:as(DirectoryNode)
209+
if not base then
209210
return
210211
end
211212

212213
M.reload_project(toplevel, nil, function()
213214
local git_status = M.get_project(toplevel)
214215

215-
Iterator.builder(root_node.nodes)
216+
Iterator.builder(base.nodes)
216217
:hidden()
217218
:applier(function(node)
218219
local parent_ignored = node.parent and node.parent:is_git_ignored() or false
@@ -224,7 +225,7 @@ local function reload_tree_at(toplevel)
224225
end)
225226
:iterate()
226227

227-
root_node.explorer.renderer:draw()
228+
base.explorer.renderer:draw()
228229
end)
229230
end
230231

@@ -248,7 +249,7 @@ function M.load_project_status(path)
248249
return status
249250
end
250251

251-
local statuses = runner({
252+
local statuses = GitRunner:run({
252253
toplevel = toplevel,
253254
list_untracked = git_utils.should_show_untracked(toplevel),
254255
list_ignored = true,

lua/nvim-tree/git/runner.lua

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@ local notify = require("nvim-tree.notify")
44

55
local Class = require("nvim-tree.class")
66

7-
---@alias GitStatusesXYByPath table<string, string>
7+
---@alias GitXYByPath table<string, string> -- short-format statuses
88

9-
---@class (exact) RunnerOpts
9+
---@class (exact) GitRunnerOpts
1010
---@field toplevel string absolute path
1111
---@field path string? absolute path
1212
---@field list_untracked boolean
1313
---@field list_ignored boolean
1414
---@field timeout integer
15-
---@field callback fun(statuses: GitStatusesXYByPath)?
15+
---@field callback fun(statuses: GitXYByPath)?
1616

17-
---@class (exact) Runner: Class
18-
---@field opts RunnerOpts
19-
---@field statuses GitStatusesXYByPath
20-
---@field rc integer? -- -1 indicates timeout
21-
local Runner = Class:new()
17+
---@class (exact) GitRunner: Class
18+
---@field private opts GitRunnerOpts
19+
---@field private statuses GitXYByPath
20+
---@field private rc integer? -- -1 indicates timeout
21+
local GitRunner = Class:new()
2222

2323
local timeouts = 0
2424
local MAX_TIMEOUTS = 5
2525

2626
---@private
2727
---@param status string
2828
---@param path string|nil
29-
function Runner:parse_status_output(status, path)
29+
function GitRunner:parse_status_output(status, path)
3030
if not path then
3131
return
3232
end
@@ -44,7 +44,7 @@ end
4444
---@param prev_output string
4545
---@param incoming string
4646
---@return string
47-
function Runner:handle_incoming_data(prev_output, incoming)
47+
function GitRunner:handle_incoming_data(prev_output, incoming)
4848
if incoming and utils.str_find(incoming, "\n") then
4949
local prev = prev_output .. incoming
5050
local i = 1
@@ -82,7 +82,7 @@ end
8282
---@param stdout_handle uv.uv_pipe_t
8383
---@param stderr_handle uv.uv_pipe_t
8484
---@return uv.spawn.options
85-
function Runner:get_spawn_options(stdout_handle, stderr_handle)
85+
function GitRunner:get_spawn_options(stdout_handle, stderr_handle)
8686
local untracked = self.opts.list_untracked and "-u" or nil
8787
local ignored = (self.opts.list_untracked and self.opts.list_ignored) and "--ignored=matching" or "--ignored=no"
8888
return {
@@ -94,7 +94,7 @@ end
9494

9595
---@private
9696
---@param output string
97-
function Runner:log_raw_output(output)
97+
function GitRunner:log_raw_output(output)
9898
if log.enabled("git") and output and type(output) == "string" then
9999
log.raw("git", "%s", output)
100100
log.line("git", "done")
@@ -103,7 +103,7 @@ end
103103

104104
---@private
105105
---@param callback function|nil
106-
function Runner:run_git_job(callback)
106+
function GitRunner:run_git_job(callback)
107107
local handle, pid
108108
local stdout = vim.loop.new_pipe(false)
109109
local stderr = vim.loop.new_pipe(false)
@@ -181,7 +181,7 @@ function Runner:run_git_job(callback)
181181
end
182182

183183
---@private
184-
function Runner:wait()
184+
function GitRunner:wait()
185185
local function is_done()
186186
return self.rc ~= nil
187187
end
@@ -191,7 +191,7 @@ function Runner:wait()
191191
end
192192

193193
---@private
194-
function Runner:finalise()
194+
function GitRunner:finalise()
195195
if self.rc == -1 then
196196
log.line("git", "job timed out %s %s", self.opts.toplevel, self.opts.path)
197197
timeouts = timeouts + 1
@@ -207,8 +207,8 @@ function Runner:finalise()
207207
end
208208
end
209209

210-
---@return GitStatusesXYByPath? statuses nil if callback present
211-
function Runner:run()
210+
---@return GitXYByPath? statuses nil if callback present
211+
function GitRunner:execute()
212212
local async = self.opts.callback ~= nil
213213
local profile = log.profile_start("git %s job %s %s", async and "async" or "sync", self.opts.toplevel, self.opts.path)
214214

@@ -238,16 +238,18 @@ function Runner:run()
238238
end
239239
end
240240

241-
---Runs a git process, which will be killed if it takes more than timeout which defaults to 400ms
242-
---@param opts RunnerOpts
243-
---@return GitStatusesXYByPath? statuses nil if callback present
244-
return function(opts)
245-
---@type Runner
241+
---Static method to run a git process, which will be killed if it takes more than timeout
242+
---@param opts GitRunnerOpts
243+
---@return GitXYByPath? statuses nil if callback present
244+
function GitRunner:run(opts)
245+
---@type GitRunner
246246
local runner = {
247247
opts = opts,
248248
statuses = {},
249249
}
250-
runner = Runner:new(runner) --[[@as Runner]]
250+
runner = GitRunner:new(runner) --[[@as GitRunner]]
251251

252-
return runner:run()
252+
return runner:execute()
253253
end
254+
255+
return GitRunner

0 commit comments

Comments
 (0)