1
0
Fork 0
mirror of synced 2024-11-30 04:35:35 -05:00
ultimate-vim/sources_non_forked/vim-go/autoload/go/lint.vim

211 lines
5.8 KiB
VimL
Raw Normal View History

2015-12-08 08:20:04 -05:00
if !exists("g:go_metalinter_command")
2016-06-26 07:12:36 -04:00
let g:go_metalinter_command = ""
2015-12-08 08:20:04 -05:00
endif
if !exists("g:go_metalinter_autosave_enabled")
2016-06-26 07:12:36 -04:00
let g:go_metalinter_autosave_enabled = ['vet', 'golint']
2015-12-08 08:20:04 -05:00
endif
if !exists("g:go_metalinter_enabled")
2016-06-26 07:12:36 -04:00
let g:go_metalinter_enabled = ['vet', 'golint', 'errcheck']
2015-12-08 08:20:04 -05:00
endif
if !exists("g:go_metalinter_deadline")
2016-06-26 07:12:36 -04:00
let g:go_metalinter_deadline = "5s"
2015-12-08 08:20:04 -05:00
endif
2014-10-31 17:30:24 -04:00
if !exists("g:go_golint_bin")
2016-06-26 07:12:36 -04:00
let g:go_golint_bin = "golint"
2014-10-31 17:30:24 -04:00
endif
2015-12-08 08:20:04 -05:00
if !exists("g:go_errcheck_bin")
2016-06-26 07:12:36 -04:00
let g:go_errcheck_bin = "errcheck"
2015-12-08 08:20:04 -05:00
endif
function! go#lint#Gometa(autosave, ...) abort
2016-06-26 07:12:36 -04:00
if a:0 == 0
let goargs = shellescape(expand('%:p:h'))
else
let goargs = go#util#Shelljoin(a:000)
endif
let meta_command = "gometalinter --disable-all"
if a:autosave || empty(g:go_metalinter_command)
let bin_path = go#path#CheckBinPath("gometalinter")
if empty(bin_path)
return
2015-12-08 08:20:04 -05:00
endif
2016-06-26 07:12:36 -04:00
if a:autosave
" include only messages for the active buffer
let meta_command .= " --include='^" . expand('%:p') . ".*$'"
2015-12-08 08:20:04 -05:00
endif
2016-06-26 07:12:36 -04:00
" linters
let linters = a:autosave ? g:go_metalinter_autosave_enabled : g:go_metalinter_enabled
for linter in linters
let meta_command .= " --enable=".linter
endfor
" deadline
let meta_command .= " --deadline=" . g:go_metalinter_deadline
" path
let meta_command .= " " . goargs
else
" the user wants something else, let us use it.
let meta_command = g:go_metalinter_command
endif
" comment out the following two lines for debugging
" echo meta_command
" return
let out = go#tool#ExecuteInDir(meta_command)
let l:listtype = "quickfix"
if go#util#ShellError() == 0
redraw | echo
call go#list#Clean(l:listtype)
call go#list#Window(l:listtype)
echon "vim-go: " | echohl Function | echon "[metalinter] PASS" | echohl None
else
" GoMetaLinter can output one of the two, so we look for both:
" <file>:<line>:[<column>]: <message> (<linter>)
" <file>:<line>:: <message> (<linter>)
" This can be defined by the following errorformat:
let errformat = "%f:%l:%c:%t%*[^:]:\ %m,%f:%l::%t%*[^:]:\ %m"
" Parse and populate our location list
call go#list#ParseFormat(l:listtype, errformat, split(out, "\n"))
let errors = go#list#Get(l:listtype)
call go#list#Window(l:listtype, len(errors))
if !a:autosave
call go#list#JumpToFirst(l:listtype)
2015-12-08 08:20:04 -05:00
endif
2016-06-26 07:12:36 -04:00
endif
2015-12-08 08:20:04 -05:00
endfunction
" Golint calls 'golint' on the current directory. Any warnings are populated in
" the location list
function! go#lint#Golint(...) abort
2016-06-26 07:12:36 -04:00
let bin_path = go#path#CheckBinPath(g:go_golint_bin)
if empty(bin_path)
return
endif
if a:0 == 0
let goargs = shellescape(expand('%'))
else
let goargs = go#util#Shelljoin(a:000)
endif
let out = go#util#System(bin_path . " " . goargs)
if empty(out)
echon "vim-go: " | echohl Function | echon "[lint] PASS" | echohl None
return
endif
let l:listtype = "quickfix"
call go#list#Parse(l:listtype, out)
let errors = go#list#Get(l:listtype)
call go#list#Window(l:listtype, len(errors))
call go#list#JumpToFirst(l:listtype)
2015-12-08 08:20:04 -05:00
endfunction
" Vet calls 'go vet' on the current directory. Any warnings are populated in
" the location list
function! go#lint#Vet(bang, ...)
2016-06-26 07:12:36 -04:00
call go#cmd#autowrite()
echon "vim-go: " | echohl Identifier | echon "calling vet..." | echohl None
if a:0 == 0
let out = go#tool#ExecuteInDir('go vet')
else
let out = go#tool#ExecuteInDir('go tool vet ' . go#util#Shelljoin(a:000))
endif
let l:listtype = "quickfix"
if go#util#ShellError() != 0
let errors = go#tool#ParseErrors(split(out, '\n'))
call go#list#Populate(l:listtype, errors)
call go#list#Window(l:listtype, len(errors))
if !empty(errors) && !a:bang
call go#list#JumpToFirst(l:listtype)
2015-12-08 08:20:04 -05:00
endif
2016-06-26 07:12:36 -04:00
echon "vim-go: " | echohl ErrorMsg | echon "[vet] FAIL" | echohl None
else
call go#list#Clean(l:listtype)
call go#list#Window(l:listtype)
redraw | echon "vim-go: " | echohl Function | echon "[vet] PASS" | echohl None
endif
2014-10-31 17:30:24 -04:00
endfunction
2015-12-08 08:20:04 -05:00
" ErrCheck calls 'errcheck' for the given packages. Any warnings are populated in
" the location list
function! go#lint#Errcheck(...) abort
2016-06-26 07:12:36 -04:00
if a:0 == 0
let goargs = go#package#ImportPath(expand('%:p:h'))
if goargs == -1
echohl Error | echomsg "vim-go: package is not inside GOPATH src" | echohl None
return
2015-12-08 08:20:04 -05:00
endif
2016-06-26 07:12:36 -04:00
else
let goargs = go#util#Shelljoin(a:000)
endif
2015-12-08 08:20:04 -05:00
2016-06-26 07:12:36 -04:00
let bin_path = go#path#CheckBinPath(g:go_errcheck_bin)
if empty(bin_path)
return
endif
echon "vim-go: " | echohl Identifier | echon "errcheck analysing ..." | echohl None
redraw
let command = bin_path . ' -abspath ' . goargs
let out = go#tool#ExecuteInDir(command)
let l:listtype = "quickfix"
if go#util#ShellError() != 0
let errformat = "%f:%l:%c:\ %m, %f:%l:%c\ %#%m"
" Parse and populate our location list
call go#list#ParseFormat(l:listtype, errformat, split(out, "\n"))
let errors = go#list#Get(l:listtype)
if empty(errors)
echohl Error | echomsg "GoErrCheck returned error" | echohl None
echo out
return
2015-12-08 08:20:04 -05:00
endif
2016-06-26 07:12:36 -04:00
if !empty(errors)
call go#list#Populate(l:listtype, errors)
call go#list#Window(l:listtype, len(errors))
if !empty(errors)
call go#list#JumpToFirst(l:listtype)
endif
2015-12-08 08:20:04 -05:00
endif
2016-06-26 07:12:36 -04:00
else
call go#list#Clean(l:listtype)
call go#list#Window(l:listtype)
echon "vim-go: " | echohl Function | echon "[errcheck] PASS" | echohl None
endif
2015-12-08 08:20:04 -05:00
endfunction
2014-10-31 17:30:24 -04:00
2016-08-02 08:48:32 -04:00
function! go#lint#ToggleMetaLinterAutoSave()
if get(g:, "go_metalinter_autosave", 0)
let g:go_metalinter_autosave = 0
call go#util#EchoProgress("auto metalinter disabled")
return
end
let g:go_metalinter_autosave = 1
call go#util#EchoProgress("auto metalinter enabled")
endfunction
2016-06-26 07:12:36 -04:00
" vim: sw=2 ts=2 et