Hi,
Per the README, I've disabled Syntastic's error checking on my Go code. I mapped the following keyboard shortcut to GoBuild:
nnoremap <leader>d :GoBuild<CR>
Previously I tried building on BufWritePre and BufWritePost, but those would occasionally require two saves to clear the errorlist.
If I run GoBuild while a test file has build errors, vim-go immediately reports SUCCESS instead of pointing out the build failure. So I switched my command to this:
function! GoSyntaxCheck()
if (match(expand("%"), "test") != 0)
:GoTestCompile
else
:GoBuild
endif
endfunction
nnoremap <leader>d :call GoSyntaxCheck()<CR>
Which does report on syntax problems in tests, but also dumps an executable in the test directory.
What command or invocation should I use to:
Hi @kevinburke
report syntax and compile failures, either automatically on file write, or with a leader command
We have two commands to get compile errors, one is being :GoBuild and second :GoTestCompile which you're using already. It's compassable and you can assigned them to anything (checkout the readme under the section mappings)
However we do not have automatic build on save feature. In long term I'm not thinking to add it, but I'm working on vim 8.0 integration, which provides async primitives. We can probably add that feature with it.
avoid adding a compiled binary in the working directory?
:GoBuild doesn't create a compiled binary. Only GoTestCompile does. Unfortunately there is no way to compile the tests without creating a binary with the go tool. But we can remove it once we create it.
I'll keep this issue open so we can track both improvements, though we might add them in separate PR's in different times
Alright :GoTestCompile doesn't create any binary anymore if you pull the latest master. For the other feature, as I said that's a future work.
@fatih not directly related to this but I remember you saying you would drop neovim support when vim would become async. Are you going to or will you leave it?
@nhooyr there is still plenty of time we have support for Vim, and even if we had it, neovim support will stay for a time. I'm still using Neovim too. So for now I'll leave it.
The vim-8.0 features are now merged and part of the v1.10 release. If you add the following and use at least Vim version 8.0.0087 you'll get build on save:
autocmd BufWritePost *.go call go#cmd#Build(1)
This will automatically run :GoBuild on every save, asynchronously in background. Thanks!
autocmd BufWritePost *.go call go#cmd#Build(1)
This will automatically run :GoBuild on every save, asynchronously in background. Thanks!
This doesn't work for *_test.go files. It runs, but returns success even when there are errors. I guess we want to run :GoTest instead of :GoBuild. What's the autocmd for that?
EDIT: I found the answer on https://github.com/fatih/vim-go/issues/1337#issuecomment-312142332: autocmd BufWritePost *_test.go :GoTest
Most helpful comment
@nhooyr there is still plenty of time we have support for Vim, and even if we had it, neovim support will stay for a time. I'm still using Neovim too. So for now I'll leave it.