Skip to content

Commit

Permalink
Merge pull request #547 from athuth/master
Browse files Browse the repository at this point in the history
Discard quickfix errors when quickfix doesn't locate a file to jump to
  • Loading branch information
fatih committed Oct 19, 2015
2 parents 497664f + 8bc21fe commit 8f11f67
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
27 changes: 24 additions & 3 deletions autoload/go/cmd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,33 @@ function! go#cmd#Run(bang, ...)
exe 'make!'
endif

cwindow
let errors = getqflist()
" 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()
let errors = []
let is_readable = {}

for item in qflist
let filename = bufname(item.bufnr)
if !has_key(is_readable, filename)
let is_readable[filename] = filereadable(filename)
endif
if is_readable[filename]
call add(errors, item)
endif
endfor

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
endfor

call setqflist(errors)
if !empty(errors) && !a:bang
cc 1 "jump to first error if there is any
endif

cwindow

let $GOPATH = old_gopath
let &makeprg = default_makeprg
endfunction
Expand Down
17 changes: 9 additions & 8 deletions compiler/go.vim
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ else
CompilerSet makeprg=go\ build
endif

CompilerSet errorformat=
\%-G#\ %.%#,
\%-G%.%#panic:\ %m,
\%Ecan\'t\ load\ package:\ %m,
\%A%f:%l:%c:\ %m,
\%A%f:%l:\ %m,
\%C%*\\s%m,
\%-G%.%#
" 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
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'
CompilerSet errorformat+=%A%f:%l:%c:\ %m " Start of multiline unspecified string is 'filename:linenumber:columnnumber:'
CompilerSet errorformat+=%A%f:%l:\ %m " Start of multiline unspecified string is 'filename:linenumber:'
CompilerSet errorformat+=%C%*\\s%m " Continuation of multiline error message is indented
CompilerSet errorformat+=%-G%.%# " All lines not matching any of the above patterns are ignored

let &cpo = s:save_cpo
unlet s:save_cpo
Expand Down

0 comments on commit 8f11f67

Please sign in to comment.