1
0
mirror of https://github.com/golang/go synced 2024-11-22 00:04:41 -07:00

vim: Send GoFmt errors to a location list

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/5043046
This commit is contained in:
Paul Sbarra 2011-09-23 09:38:10 +10:00 committed by David Symonds
parent 76d82dbc4c
commit 3dc3fa0d8c

View File

@ -17,12 +17,26 @@ command! -buffer Fmt call s:GoFormat()
function! s:GoFormat() function! s:GoFormat()
let view = winsaveview() let view = winsaveview()
%!gofmt silent %!gofmt
if v:shell_error if v:shell_error
%| " output errors returned by gofmt let errors = []
" TODO(dchest): perhaps, errors should go to quickfix for line in getline(1, line('$'))
let tokens = matchlist(line, '^\(.\{-}\):\(\d\+\):\(\d\+\)\s*\(.*\)')
if !empty(tokens)
call add(errors, {"filename": @%,
\"lnum": tokens[2],
\"col": tokens[3],
\"text": tokens[4]})
endif
endfor
if empty(errors)
% | " Couldn't detect gofmt error format, output errors
endif
undo undo
echohl Error | echomsg "Gofmt returned error" | echohl None if !empty(errors)
call setloclist(0, errors, 'r')
endif
echohl Error | echomsg "Gofmt returned error" | echohl None
endif endif
call winrestview(view) call winrestview(view)
endfunction endfunction