-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Conversation
If you need to change directory then you need to do something like let oldcd=getcwd()
exec 'lcd ' . fnameescape(expand("%:p:h"))
let makeout=SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
exec 'lcd ' . fnameescape(oldcd)
return makeout |
Perfect. Thanks! |
Hey im a bit confused. Is Also, filtering the buffer through Remove the filtering and ill pull. |
Go doesn't exactly need a style checker because it has 1 universal formatting style that is applied by the automated formatting tool package main
func main() {
s := TwoStrings{
"a member",
someStr
}
} In the snippet above
|
I understand your concerns about intrusiveness. But: Most go vimmers (vim gophers?) have an autocommand like this in their .vimrc: autocmd FileType go autocmd BufWritePre <buffer> Fmt where As ghthor explained above, it is beneficial to use Calling "============================================================================
"File: go.vim
"Description: Check go syntax using 'go build'
"Maintainer: Kamil Kisiel <kamil@kamilkisiel.net>
"License: This program is free software. It comes without any warranty,
" to the extent permitted by applicable law. You can redistribute
" it and/or modify it under the terms of the Do What The Fuck You
" Want To Public License, Version 2, as published by Sam Hocevar.
" See http://sam.zoy.org/wtfpl/COPYING for more details.
"
" Use 'let g:syntastic_go_checker_option_gofmt_write=1' to save gofmt output.
"============================================================================
function! SyntaxCheckers_go_GetLocList()
if !exists("g:syntastic_go_checker_option_gofmt_write")
let g:syntastic_go_checker_option_gofmt_write = 0
endif
if g:syntastic_go_checker_option_gofmt_write == 0
" Calling 'gofmt %' does not change the file or the buffer.
let makeprg = 'gofmt %'
else
" Calling 'gofmt -w %' reformats the file on disk if no errors are detected.
let makeprg = 'gofmt -w %'
endif
let errorformat = '%f:%l:%c: %m,%-G%.%#'
let errors = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'type': 'e'} })
if !empty(errors)
return errors
endif
if g:syntastic_go_checker_option_gofmt_write == 1
" cat seems to be robust. edit kills syntax highlighting.
let view = winsaveview()
silent %!cat %
call winrestview(view)
endif
" Files that end on '_test.go' are not compiled by 'go build'. They are
" test files and thus only compiled by 'go test'. Consequently, test files
" need to be checked with 'go test' while for the sake of lazyness, all
" other go files should be checked with 'go build'.
if match(expand('%'), '_test.go$') == 1
let makeprg = 'go test -o /dev/null'
else
let makeprg = 'go build -o /dev/null'
endif
let errorformat = '%f:%l:%c:%m,%E%f:%l:%m,%C%m,%-G#%.%#'
" 'go build' and 'go test' should be run from the directory of the file.
let popd = getcwd()
let pushd = expand('%:p:h')
exec 'lcd '.fnameescape(pushd)
let errorformat = '%f:%l:%c:%m,%E%f:%l:%m,%C%m,%-G#%.%#'
let errors = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
" Restore the current directory.
exec 'lcd '.fnameescape(popd)
return errors
endfunction By the way: |
The only reason to use I used the @ChristophMartin If you submit this change as a pull request to https://github.com/ghthor/syntastic/tree/golang-gocmd It will be reflected in this pull request or if you like I can commit it as myself crediting you. |
`go fmt` is `gofmt -l -w`, which overwrites the file. This is too intrusive to be a default behaviour.
This option allows go devs to automatically format their go sources with `gofmt -w`, which alleviates the need for an autocommand to run `%!gofmt` on BufWritePre and then run `gofmt` again for syntastic. This option is disabled by default.
Fixes for syntax_checkers/go/go.vim
* Performs better then reading from my HDD, note I do not have an SSD
Fix gofmt.vim, add gobuildtest.vim
TL;DR: Don't pull. Go support broken as of now, this pull request is not the right way to solve it. Rereading this thread and the commit history, I realized we've been approaching this the wrong way, mainly because of the confusion about what Consider the following broken go code: // ==> bar.go <==
package foo
func Bar() {
fmt.Println("Fmt package imported.") // Compile: fmt package not imported
}
// ==> foo.go <==
package foo
func Foo(n int) (int, bool) {
return n ok // Syntax: missing comma between return values; Compile: ok undefined
}
func foo(n int, ok bool) (int, bool) {
return n ok // Syntax: missing comma between return values
}
// ==> baz.go <==
package foo
func Baz() {
Bar( // Syntax: missing close paren
}
Now, both
As evident from the output, invoking
Invoking If I'm editing This is not to say that As of now, my initial motivation to introduce an option to write I apologize for making a right mess out of this. I'm about to make amends. |
I don't think there is a clean way to incorporate autocmd FileType go autocmd BufWritePre <buffer> Fmt The reasons for my initial inclusion of
The functionality I want.
This pull request fulfills my wants and with the introduction of a variable to determine I'm interested to see what you come up with as an alternative. But in defense of what we've made here my go workflow has never been more productive. |
Use #393. I'll find another way to incorporate the |
Does this work for you? https://gist.github.com/3959117 Seems to respect basic folds. |
I've made some updates to the go syntax checker via the
go
cmd.It initially checks via
go fmt
and if there are any errors it returns those. Ifgo fmt
passes then it updates the buffer by filtering throughgofmt
sincego fmt
will update formatting on disk but not in the buffer.If the go file is a test file then
go build
will not end up checking it so we check for this and instead usego test -c
which at this time will generate a test executable in the package directory namedpackagename.test
and there isn't an option to avoid creating this file but this is a quick and easy way to do syntax checking on all *.go files. It could be removed afterSyntasticMake
is called but I don't see any problem with leaving it lying around as it should be ignored by the DVCS anyway andgo clean
will remove it.There are some problems with using
go build
&go test
if you are editing a file that isn't in the current directory since they operate on the current directory. Is there a simple way tocd
to the buffers directory runlmake
and thencd
back to the original directory?