Merge pull request #393 from ChristophMartin/syntax_checkers/go
Fixes Golang Syntax Checker
This commit is contained in:
commit
aba5dd4757
@ -18,5 +18,5 @@ if exists("loaded_go_syntax_checker")
|
||||
endif
|
||||
let loaded_go_syntax_checker = 1
|
||||
|
||||
let s:supported_checkers = ["go", "6g", "gofmt"]
|
||||
let s:supported_checkers = ["go", "gofmt"]
|
||||
call SyntasticLoadChecker(s:supported_checkers, 'go')
|
||||
|
@ -1,17 +0,0 @@
|
||||
"============================================================================
|
||||
"File: 6g.vim
|
||||
"Description: Syntax checking plugin for syntastic.vim
|
||||
"Maintainer: Sam Nguyen <samxnguyen@gmail.com>
|
||||
"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.
|
||||
"
|
||||
"============================================================================
|
||||
function! SyntaxCheckers_go_GetLocList()
|
||||
let makeprg = '6g -o /dev/null %'
|
||||
let errorformat = '%E%f:%l: %m'
|
||||
|
||||
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
|
||||
endfunction
|
@ -1,6 +1,6 @@
|
||||
"============================================================================
|
||||
"File: go.vim
|
||||
"Description: Check go syntax using 'go build'
|
||||
"Description: Check go syntax using 'gofmt -l' followed by 'go [build|test]'
|
||||
"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
|
||||
@ -8,10 +8,44 @@
|
||||
" Want To Public License, Version 2, as published by Sam Hocevar.
|
||||
" See http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
"
|
||||
" This syntax checker does not reformat your source code.
|
||||
" Use a BufWritePre autocommand to that end:
|
||||
" autocmd FileType go autocmd BufWritePre <buffer> Fmt
|
||||
"============================================================================
|
||||
function! SyntaxCheckers_go_GetLocList()
|
||||
let makeprg = 'go build -o /dev/null'
|
||||
let errorformat = '%f:%l:%c:%m,%E%f:%l:%m,%C%m,%-G#%.%#'
|
||||
" Check with gofmt first, since `go build` and `go test` might not report
|
||||
" syntax errors in the current file if another file with syntax error is
|
||||
" compiled first.
|
||||
let makeprg = 'gofmt -l % 1>/dev/null'
|
||||
let errorformat = '%f:%l:%c: %m,%-G%.%#'
|
||||
let errors = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'type': 'e'} })
|
||||
|
||||
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
|
||||
if !empty(errors)
|
||||
return errors
|
||||
endif
|
||||
|
||||
" Test files, i.e. files with a name ending in `_test.go`, are not
|
||||
" compiled by `go build`, therefore `go test` must be called for those.
|
||||
if match(expand('%'), '_test.go$') == -1
|
||||
let makeprg = 'go build -o /dev/null'
|
||||
else
|
||||
let makeprg = 'go test -c -o /dev/null'
|
||||
endif
|
||||
let errorformat = '%f:%l:%c:%m,%f:%l%m,%-G#%.%#'
|
||||
|
||||
" The go compiler needs to either be run with an import path as an
|
||||
" argument or directly from the package directory. Since figuring out
|
||||
" the poper import path is fickle, just pushd/popd to the package.
|
||||
let popd = getcwd()
|
||||
let pushd = expand('%:p:h')
|
||||
"
|
||||
" pushd
|
||||
exec 'lcd ' . fnameescape(pushd)
|
||||
|
||||
let errors = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
|
||||
|
||||
" popd
|
||||
exec 'lcd ' . fnameescape(popd)
|
||||
|
||||
return errors
|
||||
endfunction
|
||||
|
@ -1,6 +1,6 @@
|
||||
"============================================================================
|
||||
"File: gofmt.vim
|
||||
"Description: Check go syntax using gofmt
|
||||
"Description: Check go syntax using 'gofmt -l'
|
||||
"Maintainer: Brandon Thomson <bt@brandonthomson.com>
|
||||
"License: This program is free software. It comes without any warranty,
|
||||
" to the extent permitted by applicable law. You can redistribute
|
||||
@ -8,9 +8,12 @@
|
||||
" Want To Public License, Version 2, as published by Sam Hocevar.
|
||||
" See http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
"
|
||||
" This syntax checker does not reformat your source code.
|
||||
" Use a BufWritePre autocommand to that end:
|
||||
" autocmd FileType go autocmd BufWritePre <buffer> Fmt
|
||||
"============================================================================
|
||||
function! SyntaxCheckers_go_GetLocList()
|
||||
let makeprg = 'gofmt %'
|
||||
let makeprg = 'gofmt -l % 1>/dev/null'
|
||||
let errorformat = '%f:%l:%c: %m,%-G%.%#'
|
||||
return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat, 'defaults': {'type': 'e'} })
|
||||
endfunction
|
||||
|
Loading…
x
Reference in New Issue
Block a user