Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replicate Syntastic behavior, or, easier go build #876

Closed
kevinburke opened this issue May 30, 2016 · 6 comments
Closed

Replicate Syntastic behavior, or, easier go build #876

kevinburke opened this issue May 30, 2016 · 6 comments

Comments

@kevinburke
Copy link

kevinburke commented May 30, 2016

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:

  • report syntax and compile failures, either automatically on file write, or with a leader command
  • avoid adding a compiled binary in the working directory?
@fatih
Copy link
Owner

fatih commented Jun 1, 2016

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

@fatih
Copy link
Owner

fatih commented Jun 1, 2016

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.

@nhooyr
Copy link
Contributor

nhooyr commented Jun 2, 2016

@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?

@fatih
Copy link
Owner

fatih commented Jun 3, 2016

@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.

@fatih
Copy link
Owner

fatih commented Nov 24, 2016

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!

@fatih fatih closed this as completed Nov 24, 2016
@porjo
Copy link

porjo commented Aug 26, 2018

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 #1337 (comment): autocmd BufWritePost *_test.go :GoTest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants