Skip to content

Commit

Permalink
Merge pull request #626 from fatih/location-list
Browse files Browse the repository at this point in the history
Location list
  • Loading branch information
fatih committed Nov 26, 2015
2 parents 3b0606c + ddfc8f4 commit 0daf802
Show file tree
Hide file tree
Showing 11 changed files with 234 additions and 212 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ disabled/enabled easily.
* Go to symbol/declaration with `:GoDef`
* Look up documentation with `:GoDoc` inside Vim or open it in browser
* Automatically import packages via `:GoImport` or plug it into autosave
* Compile your package with `:GoBuild`, install it with `:GoInstall`
* Compile your package with `:GoBuild`, install it with `:GoInstall` or test
them with `:GoTest` (also supports running single tests via `:GoTestFunc`)
* Quickly execute your current file/files with `:GoRun`
* Run `:GoTest` and see any errors in the quickfix window
* Automatic `GOPATH` detection based on the directory structure (i.e. `gb`
projects, `godep` vendored projects)
* Change or display `GOPATH` with `:GoPath`
Expand All @@ -41,6 +41,8 @@ disabled/enabled easily.
your custom vim function.
* 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.

## Install

Expand Down
84 changes: 43 additions & 41 deletions autoload/go/cmd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ function! go#cmd#Build(bang, ...)
if g:go_dispatch_enabled && exists(':Make') == 2
silent! exe 'Make'
else
silent! exe 'make!'
silent! exe 'lmake!'
endif
redraw!


let errors = getqflist()
call go#util#Cwindow(len(errors))
let errors = go#list#Get()
call go#list#Window(len(errors))

if !empty(errors)
if !a:bang
cc 1 "jump to first error if there is any
call go#list#JumpToFirst()
endif
else
redraws! | echon "vim-go: " | echohl Function | echon "[build] SUCCESS"| echohl None
Expand Down Expand Up @@ -87,16 +87,17 @@ function! go#cmd#Run(bang, ...)
if g:go_dispatch_enabled && exists(':Make') == 2
silent! exe 'Make'
else
exe 'make!'
exe 'lmake!'
endif

" Remove any nonvalid filename from the qflist to avoid opening an empty
" buffer. See https://github.com/fatih/vim-go/issues/287 for details.
let qflist = getqflist()
" Remove any nonvalid filename from the location list to avoid opening an
" empty buffer. See https://github.com/fatih/vim-go/issues/287 for
" details.
let items = go#list#Get()
let errors = []
let is_readable = {}

for item in qflist
for item in items
let filename = bufname(item.bufnr)
if !has_key(is_readable, filename)
let is_readable[filename] = filereadable(filename)
Expand All @@ -108,38 +109,37 @@ function! go#cmd#Run(bang, ...)

for k in keys(filter(is_readable, '!v:val'))
echo "vim-go: " | echohl Identifier | echon "[run] Dropped " | echohl Constant | echon '"' . k . '"'
echohl Identifier | echon " from QuickFix list (nonvalid filename)" | echohl None
echohl Identifier | echon " from location list (nonvalid filename)" | echohl None
endfor

call go#util#Cwindow(len(errors))

call setqflist(errors)
call go#list#Populate(errors)
call go#list#Window(len(errors))
if !empty(errors) && !a:bang
cc 1 "jump to first error if there is any
call go#list#JumpToFirst()
endif

let $GOPATH = old_gopath
let &makeprg = default_makeprg
endfunction

" Install installs the package by simple calling 'go install'. If any argument
" is given(which are passed directly to 'go insta'') it tries to install those
" packages. Errors are populated in the quickfix window.
" is given(which are passed directly to 'go instal') it tries to install those
" packages. Errors are populated in the location window.
function! go#cmd#Install(bang, ...)
let command = 'go install ' . go#util#Shelljoin(a:000)
call go#cmd#autowrite()
let out = go#tool#ExecuteInDir(command)
if v:shell_error
call go#tool#ShowErrors(out)
let errors = getqflist()
call go#util#Cwindow(len(errors))
let errors = go#tool#ParseErrors(split(out, '\n'))
call go#list#Populate(errors)
call go#list#Window(len(errors))
if !empty(errors) && !a:bang
cc 1 "jump to first error if there is any
call go#list#JumpToFirst()
endif
return
else
call setqflist([])
call go#util#Cwindow()
call go#list#Clean()
call go#list#Window()
endif

echon "vim-go: " | echohl Function | echon "installed to ". $GOPATH | echohl None
Expand Down Expand Up @@ -175,16 +175,16 @@ function! go#cmd#Test(bang, compile, ...)
redraw
let out = go#tool#ExecuteInDir(command)
if v:shell_error
call go#tool#ShowErrors(out)
let errors = getqflist()
call go#util#Cwindow(len(errors))
let errors = go#tool#ParseErrors(split(out, '\n'))
call go#list#Populate(errors)
call go#list#Window(len(errors))
if !empty(errors) && !a:bang
cc 1 "jump to first error if there is any
call go#list#JumpToFirst()
endif
echon "vim-go: " | echohl ErrorMsg | echon "[test] FAIL" | echohl None
else
call setqflist([])
call go#util#Cwindow()
call go#list#Clean()
call go#list#Window()

if a:compile
echon "vim-go: " | echohl Function | echon "[test] SUCCESS" | echohl None
Expand Down Expand Up @@ -233,19 +233,21 @@ function! go#cmd#Coverage(bang, ...)
call go#cmd#autowrite()
let out = go#tool#ExecuteInDir(command)
if v:shell_error
call go#tool#ShowErrors(out)
let errors = go#tool#ParseErrors(split(out, '\n'))
call go#list#Populate(errors)
call go#list#Window(len(errors))
if !empty(errors) && !a:bang
call go#list#JumpToFirst()
endif
else
" clear previous quick fix window
call setqflist([])
" clear previous location list
call go#list#Clean()
call go#list#Window()

let openHTML = 'go tool cover -html='.l:tmpname
call go#tool#ExecuteInDir(openHTML)
endif
let errors = getqflist()
call go#util#Cwindow(len(errors))
if !empty(errors) && !a:bang
cc 1 "jump to first error if there is any
endif

call delete(l:tmpname)
endfunction

Expand All @@ -269,15 +271,15 @@ function! go#cmd#Generate(bang, ...)
if g:go_dispatch_enabled && exists(':Make') == 2
silent! exe 'Make'
else
silent! exe 'make!'
silent! exe 'lmake!'
endif
redraw!

let errors = getqflist()
call go#util#Cwindow(len(errors))
let errors = go#list#Get()
call go#list#Window(len(errors))
if !empty(errors)
if !a:bang
cc 1 "jump to first error if there is any
call go#list#JumpToFirst()
endif
else
redraws! | echon "vim-go: " | echohl Function | echon "[generate] SUCCESS"| echohl None
Expand Down
22 changes: 8 additions & 14 deletions autoload/go/fmt.vim
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ if !exists("g:go_fmt_experimental")
let g:go_fmt_experimental = 0
endif

let s:got_fmt_error = 0

" we have those problems :
" http://stackoverflow.com/questions/12741977/prevent-vim-from-updating-its-undo-tree
" http://stackoverflow.com/questions/18532692/golang-formatter-and-vim-how-to-destroy-history-record?rq=1
Expand Down Expand Up @@ -105,7 +103,6 @@ function! go#fmt#Format(withGoimport)
let $GOPATH = old_gopath
endif


"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 @@ -120,16 +117,12 @@ function! go#fmt#Format(withGoimport)
let &fileformat = old_fileformat
let &syntax = &syntax

" only clear quickfix if it was previously set, this prevents closing
" other quickfixes
if s:got_fmt_error
let s:got_fmt_error = 0
call setqflist([])
call go#util#Cwindow()
endif
" clean up previous location list
call go#list#Clean()
call go#list#Window()
elseif g:go_fmt_fail_silently == 0
let splitted = split(out, '\n')
"otherwise get the errors and put them to quickfix window
"otherwise get the errors and put them to location list
let errors = []
for line in splitted
let tokens = matchlist(line, '^\(.\{-}\):\(\d\+\):\(\d\+\)\s*\(.*\)')
Expand All @@ -144,11 +137,12 @@ function! go#fmt#Format(withGoimport)
% | " Couldn't detect gofmt error format, output errors
endif
if !empty(errors)
call setqflist(errors, 'r')
call go#list#Populate(errors)
echohl Error | echomsg "Gofmt returned error" | echohl None
endif
let s:got_fmt_error = 1
call go#util#Cwindow(len(errors))

call go#list#Window(len(errors))

" We didn't use the temp file, so clean up
call delete(l:tmpname)
endif
Expand Down
71 changes: 33 additions & 38 deletions autoload/go/lint.vim
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,27 @@ function! go#lint#Gometa(...) abort

if v:shell_error == 0
redraw | echo
call setqflist([])
call go#list#Clean()
call go#list#Window()
echon "vim-go: " | echohl Function | echon "[metalinter] PASS" | echohl None
call go#util#Cwindow()
else
" backup users errorformat, will be restored once we are finished
let old_errorformat = &errorformat

" GoMetaLinter can output one of the two, so we look for both of them
" GoMetaLinter can output one of the two, so we look for both:
" <file>:<line>:[<column>]: <message> (<linter>)
" <file>:<line>:: <message> (<linter>)
let &errorformat = "%f:%l:%c:%t%*[^:]:\ %m,%f:%l::%t%*[^:]:\ %m"
" This can be defined by the following errorformat:
let errformat = "%f:%l:%c:%t%*[^:]:\ %m,%f:%l::%t%*[^:]:\ %m"

" create the quickfix list and open it
cgetexpr split(out, "\n")
let errors = getqflist()
call go#util#Cwindow(len(errors))
cc 1
" Parse and populate our location list
call go#list#ParseFormat(errformat, split(out, "\n"))

let &errorformat = old_errorformat
let errors = go#list#Get()
call go#list#Window(len(errors))
call go#list#JumpToFirst()
endif
endfunction

" Golint calls 'golint' on the current directory. Any warnings are populated in
" the quickfix window
" the location list
function! go#lint#Golint(...) abort
let bin_path = go#path#CheckBinPath(g:go_golint_bin)
if empty(bin_path)
Expand All @@ -100,14 +97,14 @@ function! go#lint#Golint(...) abort
return
endif

cgetexpr out
let errors = getqflist()
call go#util#Cwindow(len(errors))
cc 1
call go#list#Parse(out)
let errors = go#list#Get()
call go#list#Window(len(errors))
call go#list#JumpToFirst()
endfunction

" Vet calls 'go vet' on the current directory. Any warnings are populated in
" the quickfix window
" the location list
function! go#lint#Vet(bang, ...)
call go#cmd#autowrite()
echon "vim-go: " | echohl Identifier | echon "calling vet..." | echohl None
Expand All @@ -117,25 +114,22 @@ function! go#lint#Vet(bang, ...)
let out = go#tool#ExecuteInDir('go tool vet ' . go#util#Shelljoin(a:000))
endif
if v:shell_error
call go#tool#ShowErrors(out)
else
call setqflist([])
endif

let errors = getqflist()
call go#util#Cwindow(len(errors))
if !empty(errors)
if !a:bang
cc 1 "jump to first error if there is any
let errors = go#tool#ParseErrors(split(out, '\n'))
call go#list#Populate(errors)
call go#list#Window(len(errors))
if !empty(errors) && !a:bang
call go#list#JumpToFirst()
endif
echon "vim-go: " | echohl ErrorMsg | echon "[vet] FAIL" | echohl None
else
call go#util#Cwindow()
call go#list#Clean()
call go#list#Window()
redraw | echon "vim-go: " | echohl Function | echon "[vet] PASS" | echohl None
endif
endfunction

" ErrCheck calls 'errcheck' for the given packages. Any warnings are populated in
" the quickfix window.
" the location list
function! go#lint#Errcheck(...) abort
if a:0 == 0
let goargs = go#package#ImportPath(expand('%:p:h'))
Expand Down Expand Up @@ -174,18 +168,19 @@ function! go#lint#Errcheck(...) abort
if empty(errors)
echohl Error | echomsg "GoErrCheck returned error" | echohl None
echo out
return
endif

if !empty(errors)
redraw | echo
call setqflist(errors, 'r')
call go#util#Cwindow(len(errors))
cc 1 "jump to first error if there is any
call go#list#Populate(errors)
call go#list#Window(len(errors))
if !empty(errors)
call go#list#JumpToFirst()
endif
endif
else
redraw | echo
call setqflist([])
call go#util#Cwindow()
call go#list#Clean()
call go#list#Window()
echon "vim-go: " | echohl Function | echon "[errcheck] PASS" | echohl None
endif

Expand Down

0 comments on commit 0daf802

Please sign in to comment.