@@ -4,29 +4,29 @@ local notify = require("nvim-tree.notify")
4
4
5
5
local Class = require (" nvim-tree.class" )
6
6
7
- --- @alias GitStatusesXYByPath table<string , string>
7
+ --- @alias GitXYByPath table<string , string> -- short-format statuses
8
8
9
- --- @class (exact ) RunnerOpts
9
+ --- @class (exact ) GitRunnerOpts
10
10
--- @field toplevel string absolute path
11
11
--- @field path string ? absolute path
12
12
--- @field list_untracked boolean
13
13
--- @field list_ignored boolean
14
14
--- @field timeout integer
15
- --- @field callback fun ( statuses : GitStatusesXYByPath )?
15
+ --- @field callback fun ( statuses : GitXYByPath )?
16
16
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 ()
22
22
23
23
local timeouts = 0
24
24
local MAX_TIMEOUTS = 5
25
25
26
26
--- @private
27
27
--- @param status string
28
28
--- @param path string | nil
29
- function Runner :parse_status_output (status , path )
29
+ function GitRunner :parse_status_output (status , path )
30
30
if not path then
31
31
return
32
32
end
44
44
--- @param prev_output string
45
45
--- @param incoming string
46
46
--- @return string
47
- function Runner :handle_incoming_data (prev_output , incoming )
47
+ function GitRunner :handle_incoming_data (prev_output , incoming )
48
48
if incoming and utils .str_find (incoming , " \n " ) then
49
49
local prev = prev_output .. incoming
50
50
local i = 1
82
82
--- @param stdout_handle uv.uv_pipe_t
83
83
--- @param stderr_handle uv.uv_pipe_t
84
84
--- @return uv.spawn.options
85
- function Runner :get_spawn_options (stdout_handle , stderr_handle )
85
+ function GitRunner :get_spawn_options (stdout_handle , stderr_handle )
86
86
local untracked = self .opts .list_untracked and " -u" or nil
87
87
local ignored = (self .opts .list_untracked and self .opts .list_ignored ) and " --ignored=matching" or " --ignored=no"
88
88
return {
94
94
95
95
--- @private
96
96
--- @param output string
97
- function Runner :log_raw_output (output )
97
+ function GitRunner :log_raw_output (output )
98
98
if log .enabled (" git" ) and output and type (output ) == " string" then
99
99
log .raw (" git" , " %s" , output )
100
100
log .line (" git" , " done" )
103
103
104
104
--- @private
105
105
--- @param callback function | nil
106
- function Runner :run_git_job (callback )
106
+ function GitRunner :run_git_job (callback )
107
107
local handle , pid
108
108
local stdout = vim .loop .new_pipe (false )
109
109
local stderr = vim .loop .new_pipe (false )
@@ -181,7 +181,7 @@ function Runner:run_git_job(callback)
181
181
end
182
182
183
183
--- @private
184
- function Runner :wait ()
184
+ function GitRunner :wait ()
185
185
local function is_done ()
186
186
return self .rc ~= nil
187
187
end
@@ -191,7 +191,7 @@ function Runner:wait()
191
191
end
192
192
193
193
--- @private
194
- function Runner :finalise ()
194
+ function GitRunner :finalise ()
195
195
if self .rc == - 1 then
196
196
log .line (" git" , " job timed out %s %s" , self .opts .toplevel , self .opts .path )
197
197
timeouts = timeouts + 1
@@ -207,8 +207,8 @@ function Runner:finalise()
207
207
end
208
208
end
209
209
210
- --- @return GitStatusesXYByPath ? statuses nil if callback present
211
- function Runner : run ()
210
+ --- @return GitXYByPath ? statuses nil if callback present
211
+ function GitRunner : execute ()
212
212
local async = self .opts .callback ~= nil
213
213
local profile = log .profile_start (" git %s job %s %s" , async and " async" or " sync" , self .opts .toplevel , self .opts .path )
214
214
@@ -238,16 +238,18 @@ function Runner:run()
238
238
end
239
239
end
240
240
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
246
246
local runner = {
247
247
opts = opts ,
248
248
statuses = {},
249
249
}
250
- runner = Runner :new (runner ) --[[ @as Runner ]]
250
+ runner = GitRunner :new (runner ) --[[ @as GitRunner ]]
251
251
252
- return runner :run ()
252
+ return runner :execute ()
253
253
end
254
+
255
+ return GitRunner
0 commit comments