Skip to content

Commit a6cfbed

Browse files
committed
sort references
Sort references so that the list will be in order based on filename, line number, and start position. Prior to this, multiple invocations of :GoReferrers would reorder the references and any given invocation may find that references from the same file may not be in the document order.
1 parent ebffc2c commit a6cfbed

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

autoload/go/lsp.vim

+22
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,8 @@ endfunction
681681
function! s:referencesHandler(next, msg) abort dict
682682
let l:result = []
683683

684+
call sort(a:msg, funcref('s:compareLocations'))
685+
684686
for l:loc in a:msg
685687
let l:fname = go#path#FromURI(l:loc.uri)
686688
let l:line = l:loc.range.start.line+1
@@ -976,6 +978,26 @@ function! s:debug(event, data, ...) abort
976978
call timer_start(10, function('s:debugasync', [a:event, a:data]))
977979
endfunction
978980

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+
9791001
" restore Vi compatibility settings
9801002
let &cpo = s:cpo_save
9811003
unlet s:cpo_save

0 commit comments

Comments
 (0)