Skip to content

Commit

Permalink
tool: filter valid filenames, fixes #618
Browse files Browse the repository at this point in the history
  • Loading branch information
fatih committed Dec 2, 2015
1 parent 9715f28 commit 61c9b49
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 21 deletions.
23 changes: 3 additions & 20 deletions autoload/go/cmd.vim
Original file line number Diff line number Diff line change
Expand Up @@ -106,27 +106,8 @@ function! go#cmd#Run(bang, ...)
exe 'lmake!'
endif

" 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 items
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 location list (nonvalid filename)" | echohl None
endfor
let errors = go#tool#FilterValids(items)

call go#list#Populate(errors)
call go#list#Window(len(errors))
Expand Down Expand Up @@ -208,6 +189,8 @@ function! go#cmd#Test(bang, compile, ...)
let out = go#tool#ExecuteInDir(command)
if v:shell_error
let errors = go#tool#ParseErrors(split(out, '\n'))
let errors = go#tool#FilterValids(errors)

call go#list#Populate(errors)
call go#list#Window(len(errors))
if !empty(errors) && !a:bang
Expand Down
3 changes: 2 additions & 1 deletion autoload/go/jobcontrol.vim
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ function! s:on_exit(job_id, data)
return
endif


let errors = go#tool#ParseErrors(std_combined)
let errors = go#tool#FilterValids(errors)

if !len(errors)
" no errors could be past, just return
let self.state = "SUCCESS"
Expand Down
1 change: 1 addition & 0 deletions autoload/go/term.vim
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function! s:on_exit(job_id, data)
call go#list#Window()
else
let errors = go#tool#ParseErrors(job.stdout)
let errors = go#tool#FilterValids(errors)
if !empty(errors)
" close terminal we don't need it
close
Expand Down
31 changes: 31 additions & 0 deletions autoload/go/tool.vim
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,37 @@ function! go#tool#ParseErrors(lines)
return errors
endfunction

"FilterValids filters the given items with only items that have a valid
"filename. Any non valid filename is filtered out.
function! go#tool#FilterValids(items)
" 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 filtered = []
let is_readable = {}

for item in a:items
let filename = item.filename
if has_key(item, 'bufnr')
let filename = bufname(item.bufnr)
endif

if !has_key(is_readable, filename)
let is_readable[filename] = filereadable(filename)
endif
if is_readable[filename]
call add(filtered, 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 location list (nonvalid filename)" | echohl None
endfor

return filtered
endfunction

function! go#tool#ExecuteInDir(cmd) abort
let old_gopath = $GOPATH
let $GOPATH = go#path#Detect()
Expand Down

0 comments on commit 61c9b49

Please sign in to comment.