Skip to content

Commit 477a354

Browse files
committed
Job diagnostics in :GoDiag
Also: - Use :echo instead of :echom for :GoDiag. There's no reason that needs to be added to the message log as far as I can see. Probably just used :echom out of habit. - Clean up some TODOs.
1 parent 28635a1 commit 477a354

File tree

5 files changed

+53
-17
lines changed

5 files changed

+53
-17
lines changed

autoload/gopher/diag.vim

+12-2
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,20 @@ fun! gopher#diag#do(to_clipboard, ...) abort
5353

5454
" List all config variables.
5555
let l:state = add(l:state, 'VARIABLES')
56-
" TODO: wrap very long variable names a bit more nicely.
56+
" TODO: wrap very long variable values a bit more nicely.
5757
let l:state += s:indent(filter(split(execute('let'), "\n"), { i, v -> l:v =~# '^gopher_' }))
5858
let l:state = add(l:state, ' ')
5959

60+
" List running jobs.
61+
if len(gopher#system#jobs()) > 0
62+
let l:state = add(l:state, 'JOBS')
63+
for l:j in gopher#system#jobs()
64+
let l:info = job_info(l:j)
65+
let l:state = add(l:state, printf(' %s PID %d: %s', l:info['status'], l:info['process'], l:info['cmd']))
66+
endfor
67+
let l:state = add(l:state, ' ')
68+
endif
69+
6070
" List command history (if any).
6171
let l:state = add(l:state, 'COMMAND HISTORY (newest on top)')
6272
for l:h in gopher#system#history()
@@ -86,7 +96,7 @@ fun! gopher#diag#do(to_clipboard, ...) abort
8696
endif
8797

8898
for l:line in l:state
89-
echom l:line
99+
echo l:line
90100
endfor
91101
endfun
92102

autoload/gopher/guru.vim

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ fun! gopher#guru#complete(lead, cmdline, cursor) abort
1616
return gopher#compl#filter(a:lead, l:list)
1717
endfun
1818

19-
" TODO: commands need range: freevars
2019
fun! gopher#guru#do(...) abort
2120
" Prepend -scope flag unless given in the command.
21+
" TODO: commands need range: freevars
2222
let l:flags = a:000
2323
if index(l:flags, '-scope') is -1
2424
let l:flags = ['-scope', get(g:, 'gopher_guru_scope', gopher#go#package())] + l:flags

autoload/gopher/rename.vim

+22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
" rename.vim: Implement :GoRename.
22

33
" TODO: There is command-line support for 'gopls rename'
4+
"
5+
" $ gopls rename './site.go:#1029' XXX
6+
" admin.go:
7+
" package foo
8+
" [..]
9+
" init.go:
10+
" package foo
11+
" [..]
12+
"
13+
" Can also use -w to write immediately:
14+
"
15+
" $ gopls rename -w './site.go:#1029' XXX
16+
" /home/martin/code/goatcounter/admin.go
17+
" /home/martin/code/goatcounter/init.go
18+
" /home/martin/code/goatcounter/site.go
19+
" /home/martin/code/goatcounter/site_test.go
20+
" /home/martin/code/goatcounter/test.go
21+
" /home/martin/code/goatcounter/user.go
22+
"
23+
" Note: will clobber work tree with .orig files.
24+
" Limitation: only current package, not e.g. ./handlers subpackage.
25+
"
426

527
" Commandline completion: original, unexported camelCase, and exported
628
" CamelCase.

autoload/gopher/system.vim

+18-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
let s:root = expand('<sfile>:p:h:h:h') " Root dir of this plugin.
44
let s:gotools = s:root . '/tools' " Our Go tools.
55
let s:gobin = s:gotools . '/bin'
6+
let s:jobs = [] " List of running jobs.
67

78
" Command history; every item is a list with the exit code, time it took to run,
89
" command that was run, its output, and a boolean to signal it was run from
@@ -55,6 +56,12 @@ fun! gopher#system#history() abort
5556
return s:history
5657
endfun
5758

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+
5865
" Restore an environment variable back to its original value.
5966
fun! gopher#system#restore_env(name, val) abort
6067
if a:val is -1
@@ -183,7 +190,6 @@ endfun
183190
"
184191
" TODO: Don't run multiple jobs that modify the buffer at the same time. For
185192
" some tools (like gorename) we need a global lock.
186-
" TODO: allow inspecting which jobs are running (in :GoDiag?)
187193
fun! gopher#system#job(done, cmd) abort
188194
if type(a:cmd) isnot v:t_list
189195
return gopher#error('must pass a list')
@@ -206,11 +212,14 @@ fun! gopher#system#job(done, cmd) abort
206212
\ })
207213
endif
208214

209-
return job_start(a:cmd, {
215+
let l:job = job_start(a:cmd, {
210216
\ 'callback': function('s:j_out_cb', [], l:state),
211217
\ 'exit_cb': function('s:j_exit_cb', [], l:state),
212218
\ 'close_cb': function('s:j_close_cb', [], l:state),
213219
\})
220+
221+
call add(s:jobs, l:job)
222+
return l:job
214223
endfun
215224

216225
" 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
359368

360369
if self.closed
361370
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+
362378
call self.done(self.exit, self.out)
363379
endif
364380
endfun

compiler/go.vim

-12
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,10 @@ let g:current_compiler = 'go'
55
let s:save_cpo = &cpoptions
66
set cpoptions-=C
77

8-
" TODO: can probably automate the gopher_install_package better with some "go
9-
" list"-fu.
108
let &l:makeprg = printf('go install %s %s',
119
\ gopher#system#join(get(g:, 'gopher_build_flags', [])),
1210
\ get(g:, 'gopher_install_package', ''))
1311

14-
" TODO: this error isn't recognized:
15-
" # a
16-
" runtime.main_main·f: function main is undeclared in the main package
17-
18-
" TODO: this error isn't recognized:
19-
"
20-
" go: finding zgo.at/goatcounter/stripe latest
21-
" go: zgo.at/goatcounter/[email protected]: parsing go.mod: unexpected module path "zgo.at/goatcounter"
22-
" go: error loading module requirements
23-
2412
setl errorformat =%-G#\ %.%# " Ignore lines beginning with '#' ('# command-line-arguments' line sometimes appears?)
2513
setl errorformat+=%-G%.%#panic:\ %m " Ignore lines containing 'panic: message'
2614
setl errorformat+=%Ecan\'t\ load\ package:\ %m " Start of multiline error string is 'can\'t load package'

0 commit comments

Comments
 (0)