@@ -4,29 +4,29 @@ local notify = require("nvim-tree.notify")
44
55local 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
2323local timeouts = 0
2424local 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
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
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 {
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" )
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)
181181end
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()
191191end
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
208208end
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
239239end
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 ()
253253end
254+
255+ return GitRunner
0 commit comments