diff --git a/autoload/go/def.vim b/autoload/go/def.vim index 97ef79c8bd..d053615a47 100644 --- a/autoload/go/def.vim +++ b/autoload/go/def.vim @@ -42,10 +42,11 @@ function! go#def#Jump(mode) abort call extend(cmd, ["definition", fname . ':#' . go#util#OffsetCursor()]) - if go#util#has_job() + if go#util#has_job() || has('nvim') let l:spawn_args = { \ 'cmd': cmd, \ 'complete': function('s:jump_to_declaration_cb', [a:mode, bin_name]), + \ 'for': '_', \ } if &modified diff --git a/autoload/go/def_test.vim b/autoload/go/def_test.vim index 7e69b12e4b..5a8df6baaf 100644 --- a/autoload/go/def_test.vim +++ b/autoload/go/def_test.vim @@ -34,4 +34,33 @@ func! Test_jump_to_declaration_godef() abort endtry endfunc +func! Test_Jump_leaves_lists() abort + try + let filename = 'def/jump.go' + let l:tmp = gotest#load_fixture(l:filename) + + let expected = [{'lnum': 10, 'bufnr': bufnr('%'), 'col': 1, 'valid': 1, 'vcol': 0, 'nr': -1, 'type': '', 'pattern': '', 'text': 'quux'}] + + call setloclist(winnr(), copy(expected), 'r' ) + call setqflist(copy(expected), 'r' ) + + let l:bufnr = bufnr('%') + call cursor(6, 3) + call go#def#Jump('') + + let start = reltime() + while bufnr('%') == l:bufnr && reltimefloat(reltime(start)) < 10 + sleep 100m + endwhile + + let actual = getloclist(winnr()) + call gotest#assert_quickfix(actual, expected) + + let actual = getqflist() + call gotest#assert_quickfix(actual, expected) + finally + call delete(l:tmp, 'rf') + endtry +endfunc + " vim: sw=2 ts=2 et diff --git a/autoload/go/job.vim b/autoload/go/job.vim index abcd6bdb70..ffbb138978 100644 --- a/autoload/go/job.vim +++ b/autoload/go/job.vim @@ -22,6 +22,7 @@ endfunction " See statusline.vim. " 'for': " The g:go_list_type_command key to use to get the error list type to use. +" Errors will not be handled when the value is '_'. " Defaults to '_job' " 'errorformat': " The errorformat string to use when parsing errors. Defaults to @@ -184,6 +185,10 @@ function! go#job#Options(args) let cbs.close_cb = function('s:close_cb', [], state) function state.show_errors(job, exit_status, data) + if self.for == '_' + return + endif + let l:winid = win_getid(winnr()) " Always set the active window to the window that was active when the job " was started. Among other things, this makes sure that the correct @@ -225,6 +230,8 @@ function! go#job#Options(args) return endif + " only open the error window if user was still in the window from which + " the job was started. if self.winid == l:winid call go#list#Window(l:listtype, len(errors)) if !self.bang