Skip to content

Commit

Permalink
Implement Gorun and Gotest, closes #10, #16
Browse files Browse the repository at this point in the history
  • Loading branch information
fatih committed Mar 28, 2014
1 parent 8b4268c commit b0a57a3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ pre-defined sensible settings (like auto fmt on save).
* Syntax highlighting
* Autocompletion support with `<C-x><C-o>` (omnicomplete)
* Integrated and improved snippets support
* Better go fmt on save, keeps cursor position and doesn't break your undo
* Better gofmt on save, keeps cursor position and doesn't break your undo
history
* Go to symbol/declaration
* Automatically import packages
* Compile and build package
* Run quickly your snippet
* Run tests and see any errors in quick window
* Lint your code
* Advanced source analysis tool with oracle

Expand Down Expand Up @@ -89,8 +90,12 @@ Go to a declaration under your cursor or give an identifier
:Godef
:Godef <identifier>

Run go test in current directory, any errors will be populate in quickfix window

:Gotest

Build your package, it doesn't create any output binary, however it outputs any
errors (if anny) in quickfix window
errors (if ann) in quickfix window

:make

Expand Down
2 changes: 1 addition & 1 deletion compiler/go.vim
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let s:save_cpo = &cpo
set cpo-=C

" Does not produce any output binary, which is we want
let golang_makeprg = 'go\ build\ -o\ /dev/null\ ' . join(split(GoFiles(), '\n'), '\ ')
let golang_makeprg = 'go\ build\ -o\ /dev/null\ ' . join(split(g:GoFiles(), '\n'), '\ ')
exec ':CompilerSet makeprg=' . golang_makeprg
CompilerSet errorformat=
\%-G#\ %.%#,
Expand Down
44 changes: 37 additions & 7 deletions plugin/godeps.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,50 @@ if exists("g:go_loaded_godeps")
endif
let g:go_loaded_godeps = 1

function! GoFiles()
function! g:GoFiles()
let out=system("go list -f $'{{range $f := .GoFiles}}{{$.Dir}}/{{$f}}\n{{end}}'")
return out
endfunction

function! GoDeps()
function! g:GoFiles()
let out=system("go list -f $'{{range $f := .GoFiles}}{{$.Dir}}/{{$f}}\n{{end}}'")
return out
endfunction

function! s:GoDeps()
let out=system("go list -f $'{{range $f := .Deps}}{{$f}}\n{{end}}'")
return out
endfunction

function! GoRun()
exec "!go run " . join(split(GoFiles(), '\n'), ' ')
function! s:GoRun()
exec "!go run " . join(split(g:GoFiles(), '\n'), ' ')
endfunction

function! s:GoTest()
let out = system("go test .")
if v:shell_error
"otherwise get the errors and put them to quickfix window
let errors = []
for line in split(out, '\n')
let tokens = matchlist(line, '^\(.\{-}\):\(\d\+\):\s*\(.*\)')
if !empty(tokens)
call add(errors, {"filename": @%,
\"lnum": tokens[2],
\"text": tokens[3]})
endif
endfor
if empty(errors)
% | " Couldn't detect gofmt error format, output errors
endif
if !empty(errors)
call setqflist(errors, 'r')
endif
echohl Error | echomsg "Go test returned error" | echohl None
endif

endfunction

command! -buffer Gofiles echo GoFiles()
command! -buffer Godeps echo GoDeps()
command! -buffer Gorun call GoRun()
command! Gofiles echo g:GoFiles()
command! Godeps echo s:GoDeps()
command! Gorun call s:GoRun()
command! Gotest call s:GoTest()

0 comments on commit b0a57a3

Please sign in to comment.