2014-10-31 17:30:24 -04:00
|
|
|
if !exists("g:go_errcheck_bin")
|
|
|
|
let g:go_errcheck_bin = "errcheck"
|
|
|
|
endif
|
|
|
|
|
2015-01-18 07:58:28 -05:00
|
|
|
function! go#errcheck#Run(...) abort
|
|
|
|
if a:0 == 0
|
|
|
|
let package = go#package#ImportPath(expand('%:p:h'))
|
2015-02-04 05:43:54 -05:00
|
|
|
if package == -1
|
|
|
|
echohl Error | echomsg "vim-go: package is not inside GOPATH src" | echohl None
|
|
|
|
return
|
|
|
|
endif
|
2015-01-18 07:58:28 -05:00
|
|
|
else
|
|
|
|
let package = a:1
|
|
|
|
end
|
|
|
|
|
|
|
|
let bin_path = go#tool#BinPath(g:go_errcheck_bin)
|
|
|
|
if empty(bin_path)
|
|
|
|
return
|
2014-10-31 17:30:24 -04:00
|
|
|
endif
|
|
|
|
|
2015-02-04 05:43:54 -05:00
|
|
|
echon "vim-go: " | echohl Identifier | echon "errcheck analysing ..." | echohl None
|
2015-01-18 07:58:28 -05:00
|
|
|
let out = system(bin_path . ' ' . package)
|
2014-10-31 17:30:24 -04:00
|
|
|
if v:shell_error
|
|
|
|
let errors = []
|
|
|
|
let mx = '^\(.\{-}\):\(\d\+\):\(\d\+\)\s*\(.*\)'
|
|
|
|
for line in split(out, '\n')
|
|
|
|
let tokens = matchlist(line, mx)
|
|
|
|
|
|
|
|
if !empty(tokens)
|
2015-01-18 07:58:28 -05:00
|
|
|
call add(errors, {"filename": expand(DefaultGoPath() . "/src/" . tokens[1]),
|
2014-10-31 17:30:24 -04:00
|
|
|
\"lnum": tokens[2],
|
|
|
|
\"col": tokens[3],
|
|
|
|
\"text": tokens[4]})
|
|
|
|
endif
|
|
|
|
endfor
|
2015-02-04 05:43:54 -05:00
|
|
|
|
2014-10-31 17:30:24 -04:00
|
|
|
if empty(errors)
|
2015-02-04 05:43:54 -05:00
|
|
|
echohl Error | echomsg "GoErrCheck returned error" | echohl None
|
|
|
|
echo out
|
2014-10-31 17:30:24 -04:00
|
|
|
endif
|
2015-02-04 05:43:54 -05:00
|
|
|
|
2014-10-31 17:30:24 -04:00
|
|
|
if !empty(errors)
|
2015-02-04 05:43:54 -05:00
|
|
|
redraw | echo
|
2014-10-31 17:30:24 -04:00
|
|
|
call setqflist(errors, 'r')
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
call setqflist([])
|
|
|
|
endif
|
2015-02-04 05:43:54 -05:00
|
|
|
|
2014-10-31 17:30:24 -04:00
|
|
|
cwindow
|
|
|
|
endfunction
|
2015-02-04 05:43:54 -05:00
|
|
|
|
|
|
|
" vim:ts=4:sw=4:et
|