@@ -681,17 +681,26 @@ endfunction
681
681
function ! s: referencesHandler (next , msg) abort dict
682
682
let l: result = []
683
683
684
+ call sort (a: msg , funcref (' s:compareLocations' ))
685
+
684
686
for l: loc in a: msg
685
687
let l: fname = go#path#FromURI (l: loc .uri)
686
688
let l: line = l: loc .range .start .line + 1
687
689
let l: bufnr = bufnr (l: fname )
690
+ let l: bufinfo = getbufinfo (l: fname )
688
691
689
692
try
690
- if l: bufnr == -1
691
- let l: content = readfile (l: fname , ' ' , l: line )[ -1 ]
693
+ if l: bufnr == -1 || len ( l: bufinfo ) == 0 || l: bufinfo [ 0 ].loaded == 0
694
+ let l: filecontents = readfile (l: fname , ' ' , l: line )
692
695
else
693
- let l: content = getbufline (l: fname , l: line )[-1 ]
696
+ let l: filecontents = getbufline (l: fname , l: line )
697
+ endif
698
+
699
+ if len (l: filecontents ) == 0
700
+ continue
694
701
endif
702
+
703
+ let l: content = l: filecontents [-1 ]
695
704
catch
696
705
call go#util#EchoError (printf (' %s (line %s): %s at %s' , l: fname , l: line , v: exception , v: throwpoint ))
697
706
endtry
@@ -969,6 +978,26 @@ function! s:debug(event, data, ...) abort
969
978
call timer_start (10 , function (' s:debugasync' , [a: event , a: data ]))
970
979
endfunction
971
980
981
+ function ! s: compareLocations (left , right ) abort
982
+ if a: left .uri < a: right .uri
983
+ return -1
984
+ endif
985
+
986
+ if a: left .uri == a: right .uri && a: left .range .start .line < a: right .range .start .line
987
+ return -1
988
+ endif
989
+
990
+ if a: left .uri == a: right .uri && a: left .range .start .line == a: right .range .start .line && a: left .range .start .character < a: right .range .start .character
991
+ return -1
992
+ endif
993
+
994
+ if a: left .uri == a: right .uri && a: left .range .start .line == a: right .range .start .line && a: left .range .start .character == a: right .range .start .character
995
+ return 0
996
+ endif
997
+
998
+ return 1
999
+ endfunction
1000
+
972
1001
" restore Vi compatibility settings
973
1002
let &cpo = s: cpo_save
974
1003
unlet s: cpo_save
0 commit comments