Skip to content

Commit ebffc2c

Browse files
committed
resolve :GoReferrers errors
Fix errors that occurred when running :GoReferrers more than once when one of the references is in a file that is not loaded. On the first run, readline() would be used to get the contents, but then on the second run there is a buffer for the file that was previously not assigned a buffer number, but it's an unloaded buffer, so getbufline() returned an empty list.
1 parent cae1a26 commit ebffc2c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

autoload/go/lsp.vim

+10-3
Original file line numberDiff line numberDiff line change
@@ -685,13 +685,20 @@ function! s:referencesHandler(next, msg) abort dict
685685
let l:fname = go#path#FromURI(l:loc.uri)
686686
let l:line = l:loc.range.start.line+1
687687
let l:bufnr = bufnr(l:fname)
688+
let l:bufinfo = getbufinfo(l:fname)
688689

689690
try
690-
if l:bufnr == -1
691-
let l:content = readfile(l:fname, '', l:line)[-1]
691+
if l:bufnr == -1 || len(l:bufinfo) == 0 || l:bufinfo[0].loaded == 0
692+
let l:filecontents = readfile(l:fname, '', l:line)
692693
else
693-
let l:content = getbufline(l:fname, l:line)[-1]
694+
let l:filecontents = getbufline(l:fname, l:line)
694695
endif
696+
697+
if len(l:filecontents) == 0
698+
continue
699+
endif
700+
701+
let l:content = l:filecontents[-1]
695702
catch
696703
call go#util#EchoError(printf('%s (line %s): %s at %s', l:fname, l:line, v:exception, v:throwpoint))
697704
endtry

0 commit comments

Comments
 (0)