diff --git a/autoload/go/debug.vim b/autoload/go/debug.vim index 1d113017f8..e2d0b9fa36 100644 --- a/autoload/go/debug.vim +++ b/autoload/go/debug.vim @@ -12,7 +12,6 @@ if !exists('s:state') \ 'localVars': {}, \ 'functionArgs': {}, \ 'message': [], - \ 'is_test': 0, \} if go#util#HasDebug('debugger-state') @@ -507,7 +506,7 @@ function! s:out_cb(ch, msg) abort if has('nvim') let s:state['data'] = [] let l:state = {'databuf': ''} - + " explicitly bind callback to state so that within it, self will " always refer to state. See :help Partial for more information. let l:state.on_data = function('s:on_data', [], l:state) @@ -589,38 +588,23 @@ function! go#debug#Start(is_test, ...) abort endif try + let l:cmd = [ + \ dlv, + \ (a:is_test ? 'test' : 'debug'), + \] + + " append the package when it's given. if len(a:000) > 0 - let l:pkgname = a:1 - if l:pkgname[0] == '.' - let l:pkgname = go#package#FromPath(l:pkgname) + let l:pkgname = go#package#FromPath(a:1) + if l:pkgname is -1 + call go#util#EchoError('could not determine package name') + return endif - else - let l:pkgname = go#package#FromPath(getcwd()) - endif - - if l:pkgname is -1 - call go#util#EchoError('could not determine package name') - return - endif - " cd in to test directory; this is also what running "go test" does. - if a:is_test - " TODO(bc): Either remove this if it's ok to do so or else record it and - " reset cwd after the job completes. - lcd %:p:h + let l:cmd += [l:pkgname] endif - let s:state.is_test = a:is_test - - let l:args = [] - if len(a:000) > 1 - let l:args = ['--'] + a:000[1:] - endif - - let l:cmd = [ - \ dlv, - \ (a:is_test ? 'test' : 'debug'), - \ l:pkgname, + let l:cmd += [ \ '--output', tempname(), \ '--headless', \ '--api-version', '2', @@ -635,7 +619,10 @@ function! go#debug#Start(is_test, ...) abort if buildtags isnot '' let l:cmd += ['--build-flags', '--tags=' . buildtags] endif - let l:cmd += l:args + + if len(a:000) > 1 + let l:cmd += ['--'] + a:000[1:] + endif let s:state['message'] = [] let l:opts = { diff --git a/autoload/go/package.vim b/autoload/go/package.vim index ced39cc446..796f62d77e 100644 --- a/autoload/go/package.vim +++ b/autoload/go/package.vim @@ -137,7 +137,9 @@ function! go#package#ImportPath() abort endfunction -" FromPath returns the import path of arg. +" go#package#FromPath returns the import path of arg. -1 is returned when arg +" does not specify a package. -2 is returned when arg is a relative path +" outside of GOPATH and not in a module. function! go#package#FromPath(arg) abort let l:cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : 'cd' let l:dir = getcwd() @@ -156,10 +158,10 @@ function! go#package#FromPath(arg) abort let l:importpath = split(l:out, '\n')[0] - " go list returns '_CURRENTDIRECTORY' if the directory is not inside GOPATH. - " Check it and retun an error if that is the case + " go list returns '_CURRENTDIRECTORY' if the directory is neither in GOPATH + " nor in a module. Check it and retun an error if that is the case if l:importpath[0] ==# '_' - return -1 + return -2 endif return l:importpath diff --git a/doc/vim-go.txt b/doc/vim-go.txt index f552962bfb..8715995e5f 100644 --- a/doc/vim-go.txt +++ b/doc/vim-go.txt @@ -2026,8 +2026,9 @@ rest of the commands and mappings become available after starting debug mode. * Setup the debug windows according to |'g:go_debug_windows'|. * Make the `:GoDebug*` commands and `(go-debug-*)` mappings available. - The current directory is used if [pkg] is empty. Any other arguments will - be passed to the program. + The directory of the current buffer is used if [pkg] is empty. Any other + arguments will be passed to the program. When [pkg] is relative, it will + be interpreted relative to the directory of the current buffer. Use |:GoDebugStop| to stop `dlv` and exit debugging mode. @@ -2040,7 +2041,6 @@ rest of the commands and mappings become available after starting debug mode. Use `-test.flag` to pass flags to `go test` when debugging a test; for example `-test.v` or `-test.run TestFoo` - *:GoDebugRestart* :GoDebugRestart