From af43efb02126c1678b9e451ff72c71697d7b78c4 Mon Sep 17 00:00:00 2001 From: Billie Cleek Date: Thu, 15 Nov 2018 21:31:28 -0800 Subject: [PATCH 1/3] teach GoMetaLinter how to not jump to first error --- autoload/go/lint.vim | 9 +++++---- autoload/go/lint_test.vim | 6 +++--- doc/vim-go.txt | 4 +++- ftplugin/go/commands.vim | 2 +- ftplugin/go/mappings.vim | 2 +- plugin/go.vim | 2 +- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/autoload/go/lint.vim b/autoload/go/lint.vim index 18355335d7..eba911eb7c 100644 --- a/autoload/go/lint.vim +++ b/autoload/go/lint.vim @@ -2,7 +2,7 @@ let s:cpo_save = &cpo set cpo&vim -function! go#lint#Gometa(autosave, ...) abort +function! go#lint#Gometa(bang, autosave, ...) abort if a:0 == 0 let goargs = [expand('%:p:h')] else @@ -61,7 +61,7 @@ function! go#lint#Gometa(autosave, ...) abort let cmd += goargs if go#util#has_job() - call s:lint_job({'cmd': cmd}, a:autosave) + call s:lint_job({'cmd': cmd}, a:bang, a:autosave) return endif @@ -89,7 +89,7 @@ function! go#lint#Gometa(autosave, ...) abort let errors = go#list#Get(l:listtype) call go#list#Window(l:listtype, len(errors)) - if !a:autosave + if !a:autosave && !a:bang call go#list#JumpToFirst(l:listtype) endif endif @@ -200,11 +200,12 @@ function! go#lint#ToggleMetaLinterAutoSave() abort call go#util#EchoProgress("auto metalinter enabled") endfunction -function! s:lint_job(args, autosave) +function! s:lint_job(args, bang, autosave) let l:opts = { \ 'statustype': "gometalinter", \ 'errorformat': '%f:%l:%c:%t%*[^:]:\ %m,%f:%l::%t%*[^:]:\ %m', \ 'for': "GoMetaLinter", + \ 'bang': a:bang, \ } if a:autosave diff --git a/autoload/go/lint_test.vim b/autoload/go/lint_test.vim index 46acc6431f..095a9987e0 100644 --- a/autoload/go/lint_test.vim +++ b/autoload/go/lint_test.vim @@ -15,7 +15,7 @@ func! Test_Gometa() abort let g:go_metalinter_enabled = ['golint'] - call go#lint#Gometa(0, $GOPATH . '/src/foo') + call go#lint#Gometa(0, 0, $GOPATH . '/src/foo') let actual = getqflist() let start = reltime() @@ -41,7 +41,7 @@ func! Test_GometaWithDisabled() abort let g:go_metalinter_disabled = ['vet'] - call go#lint#Gometa(0, $GOPATH . '/src/foo') + call go#lint#Gometa(0, 0, $GOPATH . '/src/foo') let actual = getqflist() let start = reltime() @@ -69,7 +69,7 @@ func! Test_GometaAutoSave() abort let g:go_metalinter_autosave_enabled = ['golint'] - call go#lint#Gometa(1) + call go#lint#Gometa(0, 1) let actual = getloclist(l:winnr) let start = reltime() diff --git a/doc/vim-go.txt b/doc/vim-go.txt index dbd622f014..280e7c22bd 100644 --- a/doc/vim-go.txt +++ b/doc/vim-go.txt @@ -638,7 +638,7 @@ CTRL-t disabled it clears and stops automatic highlighting. *:GoMetaLinter* -:GoMetaLinter [path] +:GoMetaLinter! [path] Calls the underlying `gometalinter` tool and displays all warnings and errors in the |quickfix| window. By default the following linters are @@ -647,6 +647,8 @@ CTRL-t use the variable |'g:go_metalinter_command'|. To override the maximum linters execution time use |'g:go_metalinter_deadline'| variable. + If [!] is not given the first error is jumped to. + *:GoBuildTags* :GoBuildTags [tags] diff --git a/ftplugin/go/commands.vim b/ftplugin/go/commands.vim index 1fe28f3adc..9f3dbe0e23 100644 --- a/ftplugin/go/commands.vim +++ b/ftplugin/go/commands.vim @@ -77,7 +77,7 @@ command! -nargs=1 -bang -complete=customlist,go#package#Complete GoImport call g command! -nargs=* -bang -complete=customlist,go#package#Complete GoImportAs call go#import#SwitchImport(1, , '') " -- linters -command! -nargs=* GoMetaLinter call go#lint#Gometa(0, ) +command! -nargs=* -bang GoMetaLinter call go#lint#Gometa(0, 0, ) command! -nargs=0 GoMetaLinterAutoSaveToggle call go#lint#ToggleMetaLinterAutoSave() command! -nargs=* GoLint call go#lint#Golint() command! -nargs=* -bang GoVet call go#lint#Vet(0, ) diff --git a/ftplugin/go/mappings.vim b/ftplugin/go/mappings.vim index 30562c361d..b8de951ede 100644 --- a/ftplugin/go/mappings.vim +++ b/ftplugin/go/mappings.vim @@ -68,7 +68,7 @@ nnoremap (go-doc-vertical) :call go#doc#Open("vnew", "vsplit nnoremap (go-doc-split) :call go#doc#Open("new", "split") nnoremap (go-doc-browser) :call go#doc#OpenBrowser() -nnoremap (go-metalinter) :call go#lint#Gometa(0) +nnoremap (go-metalinter) :call go#lint#Gometa(!g:go_jump_to_error, 0) nnoremap (go-lint) :call go#lint#Golint() nnoremap (go-vet) :call go#lint#Vet(!g:go_jump_to_error) diff --git a/plugin/go.vim b/plugin/go.vim index d968e4a8c2..8760f8ce4a 100644 --- a/plugin/go.vim +++ b/plugin/go.vim @@ -271,7 +271,7 @@ endfunction function! s:metalinter_autosave() " run gometalinter on save if get(g:, "go_metalinter_autosave", 0) - call go#lint#Gometa(1) + call go#lint#Gometa(0, 1) endif endfunction From d5428f3e23b9fc751283cdccc2d52b99de9e4e1f Mon Sep 17 00:00:00 2001 From: Billie Cleek Date: Thu, 15 Nov 2018 21:41:36 -0800 Subject: [PATCH 2/3] teach GoLint how to not jump to first error --- autoload/go/lint.vim | 6 ++++-- doc/vim-go.txt | 4 +++- ftplugin/go/commands.vim | 2 +- ftplugin/go/mappings.vim | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/autoload/go/lint.vim b/autoload/go/lint.vim index eba911eb7c..144863fc8b 100644 --- a/autoload/go/lint.vim +++ b/autoload/go/lint.vim @@ -97,7 +97,7 @@ endfunction " Golint calls 'golint' on the current directory. Any warnings are populated in " the location list -function! go#lint#Golint(...) abort +function! go#lint#Golint(bang, ...) abort if a:0 == 0 let [l:out, l:err] = go#util#Exec([go#config#GolintBin(), go#package#ImportPath()]) else @@ -113,7 +113,9 @@ function! go#lint#Golint(...) abort call go#list#Parse(l:listtype, l:out, "GoLint") let l:errors = go#list#Get(l:listtype) call go#list#Window(l:listtype, len(l:errors)) - call go#list#JumpToFirst(l:listtype) + if !a:bang + call go#list#JumpToFirst(l:listtype) + endif endfunction " Vet calls 'go vet' on the current directory. Any warnings are populated in diff --git a/doc/vim-go.txt b/doc/vim-go.txt index 280e7c22bd..d362b1b6fa 100644 --- a/doc/vim-go.txt +++ b/doc/vim-go.txt @@ -196,11 +196,13 @@ COMMANDS *go-commands* displayed and the buffer will be untouched. *:GoLint* -:GoLint [packages] +:GoLint! [packages] Run golint for the directory under your current file, or for the given packages. + If [!] is not given the first error is jumped to. + *:GoDoc* :GoDoc [word] diff --git a/ftplugin/go/commands.vim b/ftplugin/go/commands.vim index 9f3dbe0e23..dcafbcbc5c 100644 --- a/ftplugin/go/commands.vim +++ b/ftplugin/go/commands.vim @@ -79,7 +79,7 @@ command! -nargs=* -bang -complete=customlist,go#package#Complete GoImportAs call " -- linters command! -nargs=* -bang GoMetaLinter call go#lint#Gometa(0, 0, ) command! -nargs=0 GoMetaLinterAutoSaveToggle call go#lint#ToggleMetaLinterAutoSave() -command! -nargs=* GoLint call go#lint#Golint() +command! -nargs=* -bang GoLint call go#lint#Golint(0, ) command! -nargs=* -bang GoVet call go#lint#Vet(0, ) command! -nargs=* -complete=customlist,go#package#Complete GoErrCheck call go#lint#Errcheck() diff --git a/ftplugin/go/mappings.vim b/ftplugin/go/mappings.vim index b8de951ede..1ca190073e 100644 --- a/ftplugin/go/mappings.vim +++ b/ftplugin/go/mappings.vim @@ -69,7 +69,7 @@ nnoremap (go-doc-split) :call go#doc#Open("new", "split") (go-doc-browser) :call go#doc#OpenBrowser() nnoremap (go-metalinter) :call go#lint#Gometa(!g:go_jump_to_error, 0) -nnoremap (go-lint) :call go#lint#Golint() +nnoremap (go-lint) :call go#lint#Golint(!g:go_jump_to_error) nnoremap (go-vet) :call go#lint#Vet(!g:go_jump_to_error) nnoremap (go-alternate-edit) :call go#alternate#Switch(0, "edit") From 93aa011fff00bca5b8861427b22cfc753f7a60be Mon Sep 17 00:00:00 2001 From: Billie Cleek Date: Thu, 15 Nov 2018 21:46:44 -0800 Subject: [PATCH 3/3] teach GoErrCheck how to not jump to first error --- autoload/go/lint.vim | 4 ++-- doc/vim-go.txt | 4 +++- ftplugin/go/commands.vim | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/autoload/go/lint.vim b/autoload/go/lint.vim index 144863fc8b..46effcc23f 100644 --- a/autoload/go/lint.vim +++ b/autoload/go/lint.vim @@ -149,7 +149,7 @@ endfunction " ErrCheck calls 'errcheck' for the given packages. Any warnings are populated in " the location list -function! go#lint#Errcheck(...) abort +function! go#lint#Errcheck(bang, ...) abort if a:0 == 0 let l:import_path = go#package#ImportPath() if import_path == -1 @@ -181,7 +181,7 @@ function! go#lint#Errcheck(...) abort if !empty(errors) call go#list#Populate(l:listtype, errors, 'Errcheck') call go#list#Window(l:listtype, len(errors)) - if !empty(errors) + if !a:bang call go#list#JumpToFirst(l:listtype) endif endif diff --git a/doc/vim-go.txt b/doc/vim-go.txt index d362b1b6fa..a78ace910a 100644 --- a/doc/vim-go.txt +++ b/doc/vim-go.txt @@ -466,7 +466,7 @@ CTRL-t If [!] is not given the first error is jumped to. *:GoErrCheck* -:GoErrCheck [options] +:GoErrCheck! [options] Check for unchecked errors in you current package. Errors are populated in the quickfix window. @@ -474,6 +474,8 @@ CTRL-t You may optionally pass any valid errcheck flags/options. See `errcheck -h` for a full list. + If [!] is not given the first error is jumped to. + *:GoFiles* :GoFiles [source_files] diff --git a/ftplugin/go/commands.vim b/ftplugin/go/commands.vim index dcafbcbc5c..f09754ab9d 100644 --- a/ftplugin/go/commands.vim +++ b/ftplugin/go/commands.vim @@ -81,7 +81,7 @@ command! -nargs=* -bang GoMetaLinter call go#lint#Gometa(0, 0, ) command! -nargs=0 GoMetaLinterAutoSaveToggle call go#lint#ToggleMetaLinterAutoSave() command! -nargs=* -bang GoLint call go#lint#Golint(0, ) command! -nargs=* -bang GoVet call go#lint#Vet(0, ) -command! -nargs=* -complete=customlist,go#package#Complete GoErrCheck call go#lint#Errcheck() +command! -nargs=* -bang -complete=customlist,go#package#Complete GoErrCheck call go#lint#Errcheck(0, ) " -- alternate command! -bang GoAlternate call go#alternate#Switch(0, '')