diff --git a/autoload/go/cmd.vim b/autoload/go/cmd.vim index 16d2b275e9..836059a530 100644 --- a/autoload/go/cmd.vim +++ b/autoload/go/cmd.vim @@ -1,7 +1,3 @@ -if !exists("g:go_jump_to_error") - let g:go_jump_to_error = 1 -endif - if !exists("g:go_dispatch_enabled") let g:go_dispatch_enabled = 0 endif @@ -36,16 +32,15 @@ function! go#cmd#Build(bang, ...) silent! exe 'make!' endif redraw! - if !a:bang - cwindow - let errors = getqflist() - if !empty(errors) - if g:go_jump_to_error - cc 1 "jump to first error if there is any - endif - else - redraws! | echon "vim-go: " | echohl Function | echon "[build] SUCCESS"| echohl None + + cwindow + let errors = getqflist() + if !empty(errors) + if !a:bang + cc 1 "jump to first error if there is any endif + else + redraws! | echon "vim-go: " | echohl Function | echon "[build] SUCCESS"| echohl None endif let &makeprg = default_makeprg @@ -86,14 +81,11 @@ function! go#cmd#Run(bang, ...) else exe 'make!' endif - if !a:bang - cwindow - let errors = getqflist() - if !empty(errors) - if g:go_jump_to_error - cc 1 "jump to first error if there is any - endif - endif + + cwindow + let errors = getqflist() + if !empty(errors) && !a:bang + cc 1 "jump to first error if there is any endif let $GOPATH = old_gopath @@ -103,7 +95,7 @@ endfunction " Install installs the package by simple calling 'go install'. If any argument " is given(which are passed directly to 'go insta'') it tries to install those " packages. Errors are populated in the quickfix window. -function! go#cmd#Install(...) +function! go#cmd#Install(bang, ...) let pkgs = join(a:000, '" "') let command = 'go install "' . pkgs . '"' call go#cmd#autowrite() @@ -112,10 +104,8 @@ function! go#cmd#Install(...) call go#tool#ShowErrors(out) cwindow let errors = getqflist() - if !empty(errors) - if g:go_jump_to_error - cc 1 "jump to first error if there is any - endif + if !empty(errors) && !a:bang + cc 1 "jump to first error if there is any endif return endif @@ -126,7 +116,7 @@ endfunction " Test runs `go test` in the current directory. If compile is true, it'll " compile the tests instead of running them (useful to catch errors in the " test files). Any other argument is appendend to the final `go test` command -function! go#cmd#Test(compile, ...) +function! go#cmd#Test(bang, compile, ...) let command = "go test " " don't run the test, only compile it. Useful to capture and fix errors or @@ -156,10 +146,8 @@ function! go#cmd#Test(compile, ...) call go#tool#ShowErrors(out) cwindow let errors = getqflist() - if !empty(errors) - if g:go_jump_to_error - cc 1 "jump to first error if there is any - endif + if !empty(errors) && !a:bang + cc 1 "jump to first error if there is any endif echon "vim-go: " | echohl ErrorMsg | echon "[test] FAIL" | echohl None else @@ -176,7 +164,7 @@ endfunction " Testfunc runs a single test that surrounds the current cursor position. " Arguments are passed to the `go test` command. -function! go#cmd#TestFunc(...) +function! go#cmd#TestFunc(bang, ...) " search flags legend (used only) " 'b' search backward instead of forward " 'c' accept a match at the cursor position @@ -204,12 +192,12 @@ function! go#cmd#TestFunc(...) let flag = " " . flag endif - call go#cmd#Test(0, a1, flag) + call go#cmd#Test(a:bang, 0, a1, flag) endfunction " Coverage creates a new cover profile with 'go test -coverprofile' and opens " a new HTML coverage page from that profile. -function! go#cmd#Coverage(...) +function! go#cmd#Coverage(bang, ...) let l:tmpname=tempname() let command = "go test -coverprofile=".l:tmpname @@ -226,20 +214,16 @@ function! go#cmd#Coverage(...) call go#tool#ExecuteInDir(openHTML) endif cwindow - let errors = getqflist() - if !empty(errors) - if g:go_jump_to_error - cc 1 "jump to first error if there is any - endif + if !empty(errors) && !a:bang + cc 1 "jump to first error if there is any endif - call delete(l:tmpname) endfunction " Vet calls "go vet' on the current directory. Any warnings are populated in " the quickfix window -function! go#cmd#Vet() +function! go#cmd#Vet(bang) call go#cmd#autowrite() echon "vim-go: " | echohl Identifier | echon "calling vet..." | echohl None let out = go#tool#ExecuteInDir('go vet') @@ -248,11 +232,10 @@ function! go#cmd#Vet() else call setqflist([]) endif - cwindow let errors = getqflist() - if !empty(errors) - if g:go_jump_to_error + if !empty(errors) + if !a:bang cc 1 "jump to first error if there is any endif else diff --git a/doc/vim-go.txt b/doc/vim-go.txt index 3d49578577..28e608ca50 100644 --- a/doc/vim-go.txt +++ b/doc/vim-go.txt @@ -182,7 +182,7 @@ COMMANDS *go-commands* 'xterm-clipboard' otherwise it's get yanked into the `""` register. *:GoVet* -:GoVet +:GoVet[!] Run `go vet` for the directory under your current file. Vet examines Go source code and reports suspicious constructs, such as Printf calls whose @@ -190,6 +190,8 @@ COMMANDS *go-commands* guarantee all reports are genuine problems, but it can find errors not caught by the compilers. + If [!] is not given the first error is jumped to. + *:GoDef* :GoDef [identifier] @@ -227,19 +229,23 @@ COMMANDS *go-commands* *:GoInstall* -:GoInstall +:GoInstall[!] Install your package with `go install`. + If [!] is not given the first error is jumped to. + *:GoTest* -:GoTest [expand] +:GoTest[!] [expand] Run the tests on your _test.go files via in your current directory. Errors are populated in quickfix window. If an argument is passed, 'expand' is used as file selector (useful for cases like `:GoTest ./...`). + If [!] is not given the first error is jumped to. + *:GoTestFunc* -:GoTestFunc [expand] +:GoTestFunc[!] [expand] Runs :GoTest, but only on the single test function immediate to your cursor using 'go test's '-run' flag. @@ -248,8 +254,10 @@ COMMANDS *go-commands* a matching `func Test` pattern is found or top of file is reached. Search will not wrap around when at the top of the file. + If [!] is not given the first error is jumped to. + *:GoTestCompile* -:GoTestCompile [expand] +:GoTestCompile[!] [expand] Compile your _test.go files via in your current directory. Errors are populated in quickfix window. If an argument is passed, 'expand' is used @@ -257,12 +265,16 @@ COMMANDS *go-commands* run the tests and capture/fix errors before running the tests or to create test binary. + If [!] is not given the first error is jumped to. + *:GoCoverage* -:GoCoverage +:GoCoverage[!] Create a coverage profile and open a browser to display the annotated source code of the current package. + If [!] is not given the first error is jumped to. + *:GoErrCheck* :GoErrCheck @@ -566,6 +578,18 @@ By default it's disabled > let g:go_auto_type_info = 0 < + + *'g:go_jump_to_error'* + +Use this option to enable/disable passing the bang attribute to the mappings +|(go-build)|, |(go-run)|, etc.. When enabled it will jump to the first error +automatically (means it will NOT pass the bang attribute to the appropriate +command, i.e: (go-run) -> :GoRun ). Note, that calling this doesn't have any +affect on calling the commands manually. This setting is only useful for +changing the behaviour of our custom static mappings. By default it's enabled. +> + let g:go_jump_to_error = 1 +< *'g:go_fmt_autosave'* Use this option to auto |:GoFmt| on save. By default it's enabled > @@ -599,10 +623,10 @@ fails. By default it's disabled. > Use this option to enable fmt's experimental mode. This experimental mode is superior to the current mode as it fully saves the undo history, so undo/redo -doesn't break. However it's causing problems on some Vim versions. By default -it's disabled. > +doesn't break. However it's slows (creates/deletes a file for every save) and +it's causing problems on some Vim versions. By default it's disabled. > - let g:go_fmt_experimental = 1 + let g:go_fmt_experimental = 0 < *'g:go_doc_keywordprg_enabled'* diff --git a/ftplugin/go/commands.vim b/ftplugin/go/commands.vim index 48dc95a07a..a22cc780fd 100644 --- a/ftplugin/go/commands.vim +++ b/ftplugin/go/commands.vim @@ -3,16 +3,27 @@ if exists("g:go_loaded_commands") endif let g:go_loaded_commands = 1 +" go_jump_to_error defines whether we should pass the bang attribute to the +" command or not. This is only used for mappings, because the user can't pass +" the bang attribute to the plug mappings below. So instead of hardcoding it +" as 0 (no '!' attribute) or 1 (with '!' attribute) we pass the user setting, +" which by default is enabled. For commands the user has the ability to pass +" the '!', such as :GoBuild or :GoBuild! +if !exists("g:go_jump_to_error") + let g:go_jump_to_error = 1 +endif + " Some handy plug mappings -nnoremap (go-run) :call go#cmd#Run(expand('%')) -nnoremap (go-build) :call go#cmd#Build('') -nnoremap (go-install) :call go#cmd#Install() -nnoremap (go-test) :call go#cmd#Test(0, '') -nnoremap (go-test-func) :call go#cmd#TestFunc('') -nnoremap (go-test-compile) :call go#cmd#Test(1, '') -nnoremap (go-coverage) :call go#cmd#Coverage('') -nnoremap (go-vet) :call go#cmd#Vet() +nnoremap (go-run) :call go#cmd#Run(!g:go_jump_to_error,expand('%')) +nnoremap (go-build) :call go#cmd#Build(!g:go_jump_to_error,'') +nnoremap (go-install) :call go#cmd#Install(!g:go_jump_to_error) +nnoremap (go-test) :call go#cmd#Test(!g:go_jump_to_error, 0, '') +nnoremap (go-test-func) :call go#cmd#TestFunc(!g:go_jump_to_error, '') +nnoremap (go-test-compile) :call go#cmd#Test(!g:go_jump_to_error, 1, '') +nnoremap (go-coverage) :call go#cmd#Coverage(!g:go_jump_to_error, '') +nnoremap (go-vet) :call go#cmd#Vet(!g:go_jump_to_error) + nnoremap (go-files) :call go#tool#Files() nnoremap (go-deps) :call go#tool#Deps() nnoremap (go-info) :call go#complete#Info() @@ -62,15 +73,14 @@ command! -nargs=0 GoDeps echo go#tool#Deps() command! -nargs=* GoInfo call go#complete#Info() " cmd -command! -nargs=* -bang GoRun call go#cmd#Run(0,) command! -nargs=* -bang GoBuild call go#cmd#Build(0,) -command! -nargs=* GoInstall call go#cmd#Install() -command! -nargs=* GoTest call go#cmd#Test(0, ) -command! -nargs=* GoTestFunc call go#cmd#TestFunc() -command! -nargs=* GoTestCompile call go#cmd#Test(1, ) -command! -nargs=* GoCoverage call go#cmd#Coverage() -command! -nargs=0 GoVet call go#cmd#Vet() -command! -nargs=0 GoErrCheck call go#errcheck#Run() +command! -nargs=* -bang GoRun call go#cmd#Run(0,) +command! -nargs=* -bang GoInstall call go#cmd#Install(0, ) +command! -nargs=* -bang GoTest call go#cmd#Test(0, 0, ) +command! -nargs=* -bang GoTestFunc call go#cmd#TestFunc(0, ) +command! -nargs=* -bang GoTestCompile call go#cmd#Test(0, 1, ) +command! -nargs=* -bang GoCoverage call go#cmd#Coverage(0, ) +command! -nargs=0 -bang GoVet call go#cmd#Vet(0) " -- play command! -nargs=0 -range=% GoPlay call go#play#Share(, , )