Skip to content

Commit

Permalink
Merge pull request #2056 from bhcleek/no-cursor-jump
Browse files Browse the repository at this point in the history
teach lint commands how to not jump to errors
  • Loading branch information
bhcleek committed Nov 16, 2018
2 parents 6866d08 + 93aa011 commit c2fa1a1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 20 deletions.
19 changes: 11 additions & 8 deletions autoload/go/lint.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -89,15 +89,15 @@ 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
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
Expand All @@ -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
Expand Down Expand Up @@ -147,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
Expand Down Expand Up @@ -179,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
Expand All @@ -200,11 +202,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
Expand Down
6 changes: 3 additions & 3 deletions autoload/go/lint_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 9 additions & 3 deletions doc/vim-go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -464,14 +466,16 @@ 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.

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]

Expand Down Expand Up @@ -638,7 +642,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
Expand All @@ -647,6 +651,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]

Expand Down
6 changes: 3 additions & 3 deletions ftplugin/go/commands.vim
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ 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, <f-args>, '<bang>')

" -- linters
command! -nargs=* GoMetaLinter call go#lint#Gometa(0, <f-args>)
command! -nargs=* -bang GoMetaLinter call go#lint#Gometa(<bang>0, 0, <f-args>)
command! -nargs=0 GoMetaLinterAutoSaveToggle call go#lint#ToggleMetaLinterAutoSave()
command! -nargs=* GoLint call go#lint#Golint(<f-args>)
command! -nargs=* -bang GoLint call go#lint#Golint(<bang>0, <f-args>)
command! -nargs=* -bang GoVet call go#lint#Vet(<bang>0, <f-args>)
command! -nargs=* -complete=customlist,go#package#Complete GoErrCheck call go#lint#Errcheck(<f-args>)
command! -nargs=* -bang -complete=customlist,go#package#Complete GoErrCheck call go#lint#Errcheck(<bang>0, <f-args>)

" -- alternate
command! -bang GoAlternate call go#alternate#Switch(<bang>0, '')
Expand Down
4 changes: 2 additions & 2 deletions ftplugin/go/mappings.vim
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ nnoremap <silent> <Plug>(go-doc-vertical) :<C-u>call go#doc#Open("vnew", "vsplit
nnoremap <silent> <Plug>(go-doc-split) :<C-u>call go#doc#Open("new", "split")<CR>
nnoremap <silent> <Plug>(go-doc-browser) :<C-u>call go#doc#OpenBrowser()<CR>
nnoremap <silent> <Plug>(go-metalinter) :<C-u>call go#lint#Gometa(0)<CR>
nnoremap <silent> <Plug>(go-lint) :<C-u>call go#lint#Golint()<CR>
nnoremap <silent> <Plug>(go-metalinter) :<C-u>call go#lint#Gometa(!g:go_jump_to_error, 0)<CR>
nnoremap <silent> <Plug>(go-lint) :<C-u>call go#lint#Golint(!g:go_jump_to_error)<CR>
nnoremap <silent> <Plug>(go-vet) :<C-u>call go#lint#Vet(!g:go_jump_to_error)<CR>
nnoremap <silent> <Plug>(go-alternate-edit) :<C-u>call go#alternate#Switch(0, "edit")<CR>
Expand Down
2 changes: 1 addition & 1 deletion plugin/go.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c2fa1a1

Please sign in to comment.