1
0
Fork 0
mirror of synced 2024-11-27 03:05:36 -05:00
ultimate-vim/sources_non_forked/vim-go/autoload/go/errcheck.vim

55 lines
1.4 KiB
VimL
Raw Normal View History

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
2015-07-13 06:22:46 -04:00
let bin_path = go#path#CheckBinPath(g:go_errcheck_bin)
2015-01-18 07:58:28 -05:00
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-07-13 06:22:46 -04:00
call add(errors, {"filename": expand(go#path#Default() . "/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
2015-07-13 06:22:46 -04:00
redraw | echo
2014-10-31 17:30:24 -04:00
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