Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show dlv errors in quickfix list #2111

Merged
merged 1 commit into from
Jan 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.local/
.cache/
.dlv/
.git/
.viminfo
36 changes: 26 additions & 10 deletions autoload/go/debug.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ function! s:groutineID() abort
endfunction

function! s:complete(job, exit_status, data) abort
let l:gotready = get(s:state, 'ready', 0)
" copy messages to a:data _only_ when dlv exited non-zero and it was never
" detected as ready (e.g. there was a compiler error).
if a:exit_status > 0 && !l:gotready
" copy messages to data so that vim-go's usual handling of errors from
" async jobs will occur.
call extend(a:data, s:state['message'])
endif

" return early instead of clearing any variables when the current job is not
" a:job
if has_key(s:state, 'job') && s:state['job'] != a:job
return
endif

if has_key(s:state, 'job')
call remove(s:state, 'job')
endif
Expand All @@ -38,10 +53,11 @@ function! s:complete(job, exit_status, data) abort
call remove(s:state, 'ready')
endif

call s:clearState()
if a:exit_status > 0
call go#util#EchoError(s:state['message'])
if has_key(s:state, 'ch')
call remove(s:state, 'ch')
endif

call s:clearState()
endfunction

function! s:logger(prefix, ch, msg) abort
Expand Down Expand Up @@ -217,8 +233,8 @@ endfunction
function! s:stop() abort
let l:res = s:call_jsonrpc('RPCServer.Detach', {'kill': v:true})

call s:clearState()
if has_key(s:state, 'job')
call go#job#Wait(s:state['job'])
call remove(s:state, 'job')
endif

Expand All @@ -230,9 +246,7 @@ function! s:stop() abort
call remove(s:state, 'ch')
endif

if has_key( s:state, 'data')
call remove(s:state, 'data')
endif
call s:clearState()
endfunction

function! go#debug#Stop() abort
Expand Down Expand Up @@ -570,7 +584,7 @@ function! go#debug#Start(is_test, ...) abort

" It's already running.
if has_key(s:state, 'job')
return
return s:state['job']
endif

let s:start_args = a:000
Expand Down Expand Up @@ -632,7 +646,7 @@ function! go#debug#Start(is_test, ...) abort

let s:state['message'] = []
let l:opts = {
\ 'for': '_',
\ 'for': 'GoDebug',
\ 'statustype': 'debug',
\ 'complete': function('s:complete'),
\ }
Expand All @@ -645,6 +659,8 @@ function! go#debug#Start(is_test, ...) abort
catch
call go#util#EchoError(v:exception)
endtry

return s:state['job']
endfunction

" Translate a reflect kind constant to a human string.
Expand Down Expand Up @@ -870,7 +886,7 @@ function! go#debug#Restart() abort
call go#cmd#autowrite()

try
call go#job#Stop(s:state['job'])
call s:stop()

let l:breaks = s:state['breakpoint']
let s:state = {
Expand Down
58 changes: 52 additions & 6 deletions autoload/go/debug_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,49 @@ function! Test_GoDebugStart_Empty() abort
endfunction

function! Test_GoDebugStart_RelativePackage() abort
call s:debug('./debugmain')
call s:debug('./debug/debugmain')
endfunction

function! Test_GoDebugStart_Package() abort
call s:debug('debugmain')
call s:debug('debug/debugmain')
endfunction

function! Test_GoDebugStart_Errors() abort
if !go#util#has_job()
return
endif

try
let l:expected = [
\ {'lnum': 0, 'bufnr': 0, 'col': 0, 'valid': 0, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': '# debug/compilerror'},
\ {'lnum': 6, 'bufnr': 7, 'col': 22, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': ' syntax error: unexpected newline, expecting comma or )'},
\ {'lnum': 0, 'bufnr': 0, 'col': 0, 'valid': 0, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'exit status 2'}
\]
call setqflist([], 'r')

let l:tmp = gotest#load_fixture('debug/compilerror/main.go')
call assert_false(exists(':GoDebugStop'))

let l:cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd'
execute l:cd . ' debug/compilerror'

call go#debug#Start(0)

let l:actual = getqflist()
let l:start = reltime()
while len(l:actual) == 0 && reltimefloat(reltime(l:start)) < 10
sleep 100m
let l:actual = getqflist()
endwhile

call gotest#assert_quickfix(l:actual, l:expected)
call assert_false(exists(':GoDebugStop'))

finally
call delete(l:tmp, 'rf')
" clear the quickfix lists
call setqflist([], 'r')
endtry
endfunction

function! s:debug(...) abort
Expand All @@ -20,28 +58,36 @@ function! s:debug(...) abort
endif

try
let l:tmp = gotest#load_fixture('debugmain/debugmain.go')
let l:tmp = gotest#load_fixture('debug/debugmain/debugmain.go')

call go#debug#Breakpoint(6)

call assert_false(exists(':GoDebugStop'))

if a:0 == 0
let l:cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd'
execute l:cd . ' debugmain'
call go#debug#Start(0)
execute l:cd . ' debug/debugmain'
let l:job = go#debug#Start(0)
else
call go#debug#Start(0, a:1)
let l:job = go#debug#Start(0, a:1)
endif

let l:start = reltime()
while !exists(':GoDebugStop') && reltimefloat(reltime(l:start)) < 10
sleep 100m
endwhile

call assert_true(exists(':GoDebugStop'))
call gotest#assert_quickfix(getqflist(), [])

call go#debug#Stop()

if !has('nvim')
call assert_equal(job_status(l:job), 'dead')
endif

call assert_false(exists(':GoDebugStop'))

finally
call delete(l:tmp, 'rf')
endtry
Expand Down
1 change: 1 addition & 0 deletions autoload/go/list.vim
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ endfunction
" in g:go_list_type_commands.
let s:default_list_type_commands = {
\ "GoBuild": "quickfix",
\ "GoDebug": "quickfix",
\ "GoErrCheck": "quickfix",
\ "GoFmt": "locationlist",
\ "GoGenerate": "quickfix",
Expand Down
7 changes: 7 additions & 0 deletions autoload/go/test-fixtures/debug/compilerror/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "fmt"

func main() {
fmt.Println("vim-go"
}