3
3
let s: root = expand (' <sfile>:p:h:h:h' ) " Root dir of this plugin.
4
4
let s: gotools = s: root . ' /tools' " Our Go tools.
5
5
let s: gobin = s: gotools . ' /bin'
6
+ let s: jobs = [] " List of running jobs.
6
7
7
8
" Command history; every item is a list with the exit code, time it took to run,
8
9
" command that was run, its output, and a boolean to signal it was run from
@@ -55,6 +56,12 @@ fun! gopher#system#history() abort
55
56
return s: history
56
57
endfun
57
58
59
+ " Get a list of currently running jobs. Use job_info() to get more information
60
+ " about a job.
61
+ fun ! gopher#system#jobs () abort
62
+ return s: jobs
63
+ endfun
64
+
58
65
" Restore an environment variable back to its original value.
59
66
fun ! gopher#system#restore_env (name, val) abort
60
67
if a: val is -1
@@ -183,7 +190,6 @@ endfun
183
190
"
184
191
" TODO: Don't run multiple jobs that modify the buffer at the same time. For
185
192
" some tools (like gorename) we need a global lock.
186
- " TODO: allow inspecting which jobs are running (in :GoDiag?)
187
193
fun ! gopher#system#job (done, cmd) abort
188
194
if type (a: cmd ) isnot v: t_list
189
195
return gopher#error (' must pass a list' )
@@ -206,11 +212,14 @@ fun! gopher#system#job(done, cmd) abort
206
212
\ })
207
213
endif
208
214
209
- return job_start (a: cmd , {
215
+ let l: job = job_start (a: cmd , {
210
216
\ ' callback' : function (' s:j_out_cb' , [], l: state ),
211
217
\ ' exit_cb' : function (' s:j_exit_cb' , [], l: state ),
212
218
\ ' close_cb' : function (' s:j_close_cb' , [], l: state ),
213
219
\} )
220
+
221
+ call add (s: jobs , l: job )
222
+ return l: job
214
223
endfun
215
224
216
225
" Wait for a job to finish. Note that the exit_cb or close_cb may still be
@@ -359,6 +368,13 @@ fun! s:j_exit_cb(job, exit, ...) abort dict
359
368
360
369
if self .closed
361
370
call gopher#system#_hist_ (self .cmd, self .start , self .exit , self .out, 1 )
371
+ for l: i in range (0 , len (s: jobs ) - 1 )
372
+ if s: jobs [l: i ] is a: job
373
+ call remove (s: jobs , l: i )
374
+ break
375
+ endif
376
+ endfor
377
+
362
378
call self .done (self .exit , self .out)
363
379
endif
364
380
endfun
0 commit comments