Skip to content

Commit

Permalink
list: finalize location list displaying
Browse files Browse the repository at this point in the history
  • Loading branch information
fatih committed Nov 26, 2015
1 parent 0ee6e91 commit 056a911
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 110 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
6 changes: 3 additions & 3 deletions autoload/go/cmd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ 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#list#Populate(errors)
Expand All @@ -123,8 +123,8 @@ function! go#cmd#Run(bang, ...)
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()
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 @@ -106,7 +104,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 @@ -119,16 +116,12 @@ function! go#fmt#Format(withGoimport)
silent edit!
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 @@ -143,11 +136,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
45 changes: 21 additions & 24 deletions autoload/go/oracle.vim
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ if !exists("g:go_oracle_bin")
endif

" Parses (via regex) Oracle's 'plain' format output and puts them into a
" quickfix list.
func! s:qflist(output)
let qflist = []
" location list
func! s:loclist(output)
let llist = []
" Parse GNU-style 'file:line.col-line.col: message' format.
let mx = '^\(\a:[\\/][^:]\+\|[^:]\+\):\(\d\+\):\(\d\+\):\(.*\)$'
for line in split(a:output, "\n")
Expand All @@ -33,17 +33,17 @@ func! s:qflist(output)
if bnr != -1
let item['bufnr'] = bnr
endif
call add(qflist, item)
call add(llist, item)
endfor
call setqflist(qflist)
call go#util#Cwindow(len(qflist))
call go#list#Populate(llist)
call go#list#Window(len(llist))
endfun

" This uses Vim's errorformat to parse the output from Oracle's 'plain output
" and put it into quickfix list. I believe using errorformat is much more
" and put it into location list. I believe using errorformat is much more
" easier to use. If we need more power we can always switch back to parse it
" via regex.
func! s:qflistSecond(output)
func! s:loclistSecond(output)
" backup users errorformat, will be restored once we are finished
let old_errorformat = &errorformat

Expand All @@ -53,16 +53,13 @@ func! s:qflistSecond(output)
" 'file:line:col: message'
"
" We discard line2 and col2 for the first errorformat, because it's not
" useful and quickfix only has the ability to show one line and column
" useful and location only has the ability to show one line and column
" number
let &errorformat = "%f:%l.%c-%[%^:]%#:\ %m,%f:%l:%c:\ %m"
let errformat = "%f:%l.%c-%[%^:]%#:\ %m,%f:%l:%c:\ %m"
call go#list#ParseFormat(errformat, split(a:output, "\n"))

" create the quickfix list and open it
cgetexpr split(a:output, "\n")
let errors = getqflist()
call go#util#Cwindow(len(errors))

let &errorformat = old_errorformat
let errors = go#list#Get()
call go#list#Window(len(errors))
endfun

func! s:getpos(l, c)
Expand Down Expand Up @@ -186,31 +183,31 @@ endfunction
" Show 'implements' relation for selected package
function! go#oracle#Implements(selected)
let out = s:RunOracle('implements', a:selected, 0)
call s:qflistSecond(out)
call s:loclistSecond(out)
endfunction

" Describe selected syntax: definition, methods, etc
function! go#oracle#Describe(selected)
let out = s:RunOracle('describe', a:selected, 0)
call s:qflistSecond(out)
call s:loclistSecond(out)
endfunction

" Show possible targets of selected function call
function! go#oracle#Callees(selected)
let out = s:RunOracle('callees', a:selected, 1)
call s:qflistSecond(out)
call s:loclistSecond(out)
endfunction

" Show possible callers of selected function
function! go#oracle#Callers(selected)
let out = s:RunOracle('callers', a:selected, 1)
call s:qflistSecond(out)
call s:loclistSecond(out)
endfunction

" Show path from callgraph root to selected function
function! go#oracle#Callstack(selected)
let out = s:RunOracle('callstack', a:selected, 1)
call s:qflistSecond(out)
call s:loclistSecond(out)
endfunction

" Show free variables of selection
Expand All @@ -222,19 +219,19 @@ function! go#oracle#Freevars(selected)
endif

let out = s:RunOracle('freevars', a:selected, 0)
call s:qflistSecond(out)
call s:loclistSecond(out)
endfunction

" Show send/receive corresponding to selected channel op
function! go#oracle#ChannelPeers(selected)
let out = s:RunOracle('peers', a:selected, 1)
call s:qflistSecond(out)
call s:loclistSecond(out)
endfunction

" Show all refs to entity denoted by selected identifier
function! go#oracle#Referrers(selected)
let out = s:RunOracle('referrers', a:selected, 0)
call s:qflistSecond(out)
call s:loclistSecond(out)
endfunction

" vim:ts=4:sw=4:et
Expand Down
16 changes: 9 additions & 7 deletions autoload/go/rename.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function! go#rename#Rename(bang, ...)
let to = a:1
endif


"return with a warning if the bin doesn't exist
let bin_path = go#path#CheckBinPath(g:go_gorename_bin)
if empty(bin_path)
Expand All @@ -31,20 +30,23 @@ function! go#rename#Rename(bang, ...)
let clean = split(out, '\n')

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()
redraw | echon "vim-go: " | echohl Function | echon clean[0] | echohl None
endif

" refresh the buffer so we can see the new content
" TODO(arslan): also find all other buffers and refresh them too. For this
" we need a way to get the list of changes from gorename upon an success
" change.
silent execute ":e"
endfunction

Expand Down
27 changes: 0 additions & 27 deletions autoload/go/tool.vim
Original file line number Diff line number Diff line change
Expand Up @@ -65,33 +65,6 @@ function! go#tool#ParseErrors(lines)
return errors
endfunction


function! go#tool#ShowErrors(out)
" cd into the current files directory. This is important so fnamemodify
" does create a full path for outputs when the token is only a single file
" name (such as for a go test output, i.e.: 'demo_test.go'). For other
" outputs, such as 'go install' we already get an absolute path (i.e.:
" '../foo/foo.go') and fnamemodify successfuly creates the full path.
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
let current_dir = getcwd()
execute cd . fnameescape(expand("%:p:h"))

let errors = go#tool#ParseErrors(split(a:out, '\n'))

" return back to old dir once we are finished with populating the errors
execute cd . fnameescape(current_dir)

if !empty(errors)
call setqflist(errors, 'r')
return
endif

if empty(errors)
" Couldn't detect error format, output errors
echo a:out
endif
endfunction

function! go#tool#ExecuteInDir(cmd) abort
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
Expand Down
8 changes: 6 additions & 2 deletions compiler/go.vim
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ else
CompilerSet makeprg=go\ build
endif

" Define the patterns that will be recognized by QuickFix when parsing the output of GoRun.
" More information at http://vimdoc.sourceforge.net/htmldoc/quickfix.html#errorformat
" Define the patterns that will be recognized by QuickFix when parsing the
" output of Go command that use this errorforamt (when called make, cexpr or
" lmake, lexpr). This is the global errorformat, however some command might
" use a different output, for those we define them directly and modify the
" errorformat ourselves. More information at:
" http://vimdoc.sourceforge.net/htmldoc/quickfix.html#errorformat
CompilerSet errorformat =%-G#\ %.%# " Ignore lines beginning with '#' ('# command-line-arguments' line sometimes appears?)
CompilerSet errorformat+=%-G%.%#panic:\ %m " Ignore lines containing 'panic: message'
CompilerSet errorformat+=%Ecan\'t\ load\ package:\ %m " Start of multiline error string is 'can\'t load package'
Expand Down
Loading

0 comments on commit 056a911

Please sign in to comment.