diff --git a/autoload/go/cmd.vim b/autoload/go/cmd.vim index fbb914064b..87312806d9 100644 --- a/autoload/go/cmd.vim +++ b/autoload/go/cmd.vim @@ -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)) @@ -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 diff --git a/autoload/go/jobcontrol.vim b/autoload/go/jobcontrol.vim index a574c18aef..a52c5026fa 100644 --- a/autoload/go/jobcontrol.vim +++ b/autoload/go/jobcontrol.vim @@ -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" diff --git a/autoload/go/term.vim b/autoload/go/term.vim index 3c7ac8fa1f..9d0b13a936 100644 --- a/autoload/go/term.vim +++ b/autoload/go/term.vim @@ -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 diff --git a/autoload/go/tool.vim b/autoload/go/tool.vim index 12206ee4b0..7cfa6b0c60 100644 --- a/autoload/go/tool.vim +++ b/autoload/go/tool.vim @@ -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()