Skip to content

Commit

Permalink
Merge pull request #700 from bhcleek/master
Browse files Browse the repository at this point in the history
support configurable list types
  • Loading branch information
fatih committed Feb 11, 2016
2 parents af1c4dd + 62feccf commit ff1e5f3
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 135 deletions.
13 changes: 0 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ disabled/enabled easily.
* Go asm formatting on save
* Tagbar support to show tags of the source code in a sidebar with `gotags`
* Custom vim text objects such as `a function` or `inner function`
* All commands support collecting and displaying errors in Vim's location
list.
* A async launcher for the go command is implemented for Neovim, fully async
building and testing (beta).
Expand Down Expand Up @@ -214,18 +213,6 @@ let g:go_bin_path = expand("~/.gotools")
let g:go_bin_path = "/home/fatih/.mypath" "or give absolute path
```

### Location list navigation

All commands support collecting and displaying errors in Vim's location list.

Quickly navigate through these location lists with `:lne` for next error and `:lp`
for previous. You can also bind these to keys, for example:

```vim
map <C-n> :lne<CR>
map <C-m> :lp<CR>
```

### Using with Neovim (beta)

Note: Neovim currently is not a first class citizen for vim-go. You are free
Expand Down
72 changes: 45 additions & 27 deletions autoload/go/cmd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function! go#cmd#Build(bang, ...)
let default_makeprg = &makeprg
let &makeprg = "go " . join(args, ' ')

let l:listtype = go#list#Type("quickfix")
" execute make inside the source folder so we can parse the errors
" correctly
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
Expand All @@ -46,20 +47,22 @@ function! go#cmd#Build(bang, ...)
if g:go_dispatch_enabled && exists(':Make') == 2
call go#util#EchoProgress("building dispatched ...")
silent! exe 'Make'
else
elseif l:listtype == "locationlist"
silent! exe 'lmake!'
else
silent! exe 'make!'
endif
redraw!
finally
execute cd . fnameescape(dir)
endtry

let errors = go#list#Get()
call go#list#Window(len(errors))
let errors = go#list#Get(l:listtype)
call go#list#Window(l:listtype, len(errors))

if !empty(errors)
if !a:bang
call go#list#JumpToFirst()
call go#list#JumpToFirst(l:listtype)
endif
else
call go#util#EchoSuccess("[build] SUCCESS")
Expand Down Expand Up @@ -109,19 +112,23 @@ function! go#cmd#Run(bang, ...)
let &makeprg = "go run " . go#util#Shelljoin(map(copy(a:000), "expand(v:val)"), 1)
endif

let l:listtype = go#list#Type("quickfix")

if g:go_dispatch_enabled && exists(':Make') == 2
silent! exe 'Make'
elseif l:listtype == "locationlist"
silent! exe 'lmake!'
else
exe 'lmake!'
silent! exe 'make!'
endif

let items = go#list#Get()
let items = go#list#Get(l:listtype)
let errors = go#tool#FilterValids(items)

call go#list#Populate(errors)
call go#list#Window(len(errors))
call go#list#Populate(l:listtype, errors)
call go#list#Window(l:listtype, len(errors))
if !empty(errors) && !a:bang
call go#list#JumpToFirst()
call go#list#JumpToFirst(l:listtype)
endif

let $GOPATH = old_gopath
Expand All @@ -138,6 +145,7 @@ function! go#cmd#Install(bang, ...)
let goargs = go#util#Shelljoin(map(copy(a:000), "expand(v:val)"), 1)
let &makeprg = "go install " . goargs

let l:listtype = go#list#Type("quickfix")
" execute make inside the source folder so we can parse the errors
" correctly
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
Expand All @@ -147,19 +155,21 @@ function! go#cmd#Install(bang, ...)
if g:go_dispatch_enabled && exists(':Make') == 2
call go#util#EchoProgress("building dispatched ...")
silent! exe 'Make'
else
elseif l:listtype == "locationlist"
silent! exe 'lmake!'
else
silent! exe 'make!'
endif
redraw!
finally
execute cd . fnameescape(dir)
endtry

let errors = go#list#Get()
call go#list#Window(len(errors))
let errors = go#list#Get(l:listtype)
call go#list#Window(l:listtype, len(errors))
if !empty(errors)
if !a:bang
call go#list#JumpToFirst()
call go#list#JumpToFirst(l:listtype)
endif
else
redraws! | echon "vim-go: " | echohl Function | echon "installed to ". $GOPATH | echohl None
Expand Down Expand Up @@ -213,6 +223,8 @@ function! go#cmd#Test(bang, compile, ...)

let out = go#tool#ExecuteInDir(command)

let l:listtype = "quickfix"

if v:shell_error
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
let dir = getcwd()
Expand All @@ -224,18 +236,18 @@ function! go#cmd#Test(bang, compile, ...)
execute cd . fnameescape(dir)
endtry

call go#list#Populate(errors)
call go#list#Window(len(errors))
call go#list#Populate(l:listtype, errors)
call go#list#Window(l:listtype, len(errors))
if !empty(errors) && !a:bang
call go#list#JumpToFirst()
call go#list#JumpToFirst(l:listtype)
elseif empty(errors)
" failed to parse errors, output the original content
call go#util#EchoError(out)
endif
echon "vim-go: " | echohl ErrorMsg | echon "[test] FAIL" | echohl None
else
call go#list#Clean()
call go#list#Window()
call go#list#Clean(l:listtype)
call go#list#Window(l:listtype)

if a:compile
echon "vim-go: " | echohl Function | echon "[test] SUCCESS" | echohl None
Expand Down Expand Up @@ -281,19 +293,21 @@ function! go#cmd#Coverage(bang, ...)

let command = "go test -coverprofile=" . l:tmpname . ' ' . go#util#Shelljoin(a:000)


let l:listtype = "quickfix"
call go#cmd#autowrite()
let out = go#tool#ExecuteInDir(command)
if v:shell_error
let errors = go#tool#ParseErrors(split(out, '\n'))
call go#list#Populate(errors)
call go#list#Window(len(errors))
call go#list#Populate(l:listtype, errors)
call go#list#Window(l:listtype, len(errors))
if !empty(errors) && !a:bang
call go#list#JumpToFirst()
call go#list#JumpToFirst(l:listtype)
endif
else
" clear previous location list
call go#list#Clean()
call go#list#Window()
call go#list#Clean(l:listtype)
call go#list#Window(l:listtype)

let openHTML = 'go tool cover -html='.l:tmpname
call go#tool#ExecuteInDir(openHTML)
Expand All @@ -318,19 +332,23 @@ function! go#cmd#Generate(bang, ...)
let &makeprg = "go generate " . goargs . ' ' . gofiles
endif

let l:listtype = go#list#Type("quickfix")

echon "vim-go: " | echohl Identifier | echon "generating ..."| echohl None
if g:go_dispatch_enabled && exists(':Make') == 2
silent! exe 'Make'
else
elseif l:listtype == "locationlist"
silent! exe 'lmake!'
else
silent! exe 'make!'
endif
redraw!

let errors = go#list#Get()
call go#list#Window(len(errors))
let errors = go#list#Get(l:listtype)
call go#list#Window(l:listtype, len(errors))
if !empty(errors)
if !a:bang
call go#list#JumpToFirst()
call go#list#JumpToFirst(l:listtype)
endif
else
redraws! | echon "vim-go: " | echohl Function | echon "[generate] SUCCESS"| echohl None
Expand Down
9 changes: 5 additions & 4 deletions autoload/go/fmt.vim
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function! go#fmt#Format(withGoimport)
let $GOPATH = old_gopath
endif

let l:listtype = "locationlist"
"if there is no error on the temp file replace the output with the current
"file (if this fails, we can always check the outputs first line with:
"splitted =~ 'package \w\+')
Expand All @@ -122,8 +123,8 @@ function! go#fmt#Format(withGoimport)
" clean up previous location list, but only if it's due fmt
if s:got_fmt_error
let s:got_fmt_error = 0
call go#list#Clean()
call go#list#Window()
call go#list#Clean(l:listtype)
call go#list#Window(l:listtype)
endif
elseif g:go_fmt_fail_silently == 0
let splitted = split(out, '\n')
Expand All @@ -142,12 +143,12 @@ function! go#fmt#Format(withGoimport)
% | " Couldn't detect gofmt error format, output errors
endif
if !empty(errors)
call go#list#Populate(errors)
call go#list#Populate(l:listtype, errors)
echohl Error | echomsg "Gofmt returned error" | echohl None
endif

let s:got_fmt_error = 1
call go#list#Window(len(errors))
call go#list#Window(l:listtype, len(errors))

" We didn't use the temp file, so clean up
call delete(l:tmpname)
Expand Down
11 changes: 6 additions & 5 deletions autoload/go/jobcontrol.vim
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ endfunction
function! s:on_exit(job_id, exit_status)
let std_combined = self.stderr + self.stdout
if a:exit_status == 0
call go#list#Clean()
call go#list#Window()
call go#list#Clean(0)
call go#list#Window(0)

let self.state = "SUCCESS"
call go#util#EchoSuccess("SUCCESS")
Expand Down Expand Up @@ -125,10 +125,11 @@ function! s:on_exit(job_id, exit_status)

" if we are still in the same windows show the list
if self.winnr == winnr()
call go#list#Populate(errors)
call go#list#Window(len(errors))
let l:listtype = "locationlist"
call go#list#Populate(l:listtype, errors)
call go#list#Window(l:listtype, len(errors))
if !empty(errors) && !self.bang
call go#list#JumpToFirst()
call go#list#JumpToFirst(l:listtype)
endif
endif
endfunction
Expand Down
49 changes: 27 additions & 22 deletions autoload/go/lint.vim
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ function! go#lint#Gometa(autosave, ...) abort

let out = go#tool#ExecuteInDir(meta_command)

let l:listtype = "quickfix"
if v:shell_error == 0
redraw | echo
call go#list#Clean()
call go#list#Window()
call go#list#Clean(l:listtype)
call go#list#Window(l:listtype)
echon "vim-go: " | echohl Function | echon "[metalinter] PASS" | echohl None
else
" GoMetaLinter can output one of the two, so we look for both:
Expand All @@ -76,13 +77,13 @@ function! go#lint#Gometa(autosave, ...) abort
let errformat = "%f:%l:%c:%t%*[^:]:\ %m,%f:%l::%t%*[^:]:\ %m"

" Parse and populate our location list
call go#list#ParseFormat(errformat, split(out, "\n"))
call go#list#ParseFormat(l:listtype, errformat, split(out, "\n"))

let errors = go#list#Get()
call go#list#Window(len(errors))
let errors = go#list#Get(l:listtype)
call go#list#Window(l:listtype, len(errors))

if !a:autosave
call go#list#JumpToFirst()
call go#list#JumpToFirst(l:listtype)
endif
endif
endfunction
Expand All @@ -107,10 +108,11 @@ function! go#lint#Golint(...) abort
return
endif

call go#list#Parse(out)
let errors = go#list#Get()
call go#list#Window(len(errors))
call go#list#JumpToFirst()
let l:listtype = "quickfix"
call go#list#Parse(l:listtype, out)
let errors = go#list#Get(l:listtype)
call go#list#Window(l:listtype, len(errors))
call go#list#JumpToFirst(l:listtype)
endfunction

" Vet calls 'go vet' on the current directory. Any warnings are populated in
Expand All @@ -123,17 +125,19 @@ function! go#lint#Vet(bang, ...)
else
let out = go#tool#ExecuteInDir('go tool vet ' . go#util#Shelljoin(a:000))
endif

let l:listtype = "quickfix"
if v:shell_error
let errors = go#tool#ParseErrors(split(out, '\n'))
call go#list#Populate(errors)
call go#list#Window(len(errors))
call go#list#Populate(l:listtype, errors)
call go#list#Window(l:listtype, len(errors))
if !empty(errors) && !a:bang
call go#list#JumpToFirst()
call go#list#JumpToFirst(l:listtype)
endif
echon "vim-go: " | echohl ErrorMsg | echon "[vet] FAIL" | echohl None
else
call go#list#Clean()
call go#list#Window()
call go#list#Clean(l:listtype)
call go#list#Window(l:listtype)
redraw | echon "vim-go: " | echohl Function | echon "[vet] PASS" | echohl None
endif
endfunction
Expand Down Expand Up @@ -162,13 +166,14 @@ function! go#lint#Errcheck(...) abort
let command = bin_path . ' -abspath ' . goargs
let out = go#tool#ExecuteInDir(command)

let l:listtype = "quickfix"
if v:shell_error
let errformat = "%f:%l:%c:\ %m, %f:%l:%c\ %#%m"

" Parse and populate our location list
call go#list#ParseFormat(errformat, split(out, "\n"))
call go#list#ParseFormat(l:listtype, errformat, split(out, "\n"))

let errors = go#list#Get()
let errors = go#list#Get(l:listtype)

if empty(errors)
echohl Error | echomsg "GoErrCheck returned error" | echohl None
Expand All @@ -177,15 +182,15 @@ function! go#lint#Errcheck(...) abort
endif

if !empty(errors)
call go#list#Populate(errors)
call go#list#Window(len(errors))
call go#list#Populate(l:listtype, errors)
call go#list#Window(l:listtype, len(errors))
if !empty(errors)
call go#list#JumpToFirst()
call go#list#JumpToFirst(l:listtype)
endif
endif
else
call go#list#Clean()
call go#list#Window()
call go#list#Clean(l:listtype)
call go#list#Window(l:listtype)
echon "vim-go: " | echohl Function | echon "[errcheck] PASS" | echohl None
endif

Expand Down
Loading

0 comments on commit ff1e5f3

Please sign in to comment.