]> Cypherpunks repositories - gostls13.git/commitdiff
vim: Send GoFmt errors to a location list
authorPaul Sbarra <Sbarra.Paul@gmail.com>
Thu, 22 Sep 2011 23:38:10 +0000 (09:38 +1000)
committerDavid Symonds <dsymonds@golang.org>
Thu, 22 Sep 2011 23:38:10 +0000 (09:38 +1000)
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/5043046

misc/vim/ftplugin/go/fmt.vim

index a299dfcee7da84ffdfa512c3311330788a7dd25f..0ee44cd59ef8e1c448e9ad19252833548c08a899 100644 (file)
@@ -17,12 +17,26 @@ command! -buffer Fmt call s:GoFormat()
 
 function! s:GoFormat()
     let view = winsaveview()
-    %!gofmt
+    silent %!gofmt
     if v:shell_error
-        %| " output errors returned by gofmt
-           " TODO(dchest): perhaps, errors should go to quickfix
+        let errors = []
+        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
-       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
     call winrestview(view)
 endfunction