Skip to content

Commit ac1b780

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 ac1b780

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
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

doc/vim-go.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -1407,11 +1407,11 @@ and `guru`.
14071407
<
14081408
*'g:go_referrers_mode'*
14091409

1410-
Use this option to define the command to be used for |:GoReferrers|. By default
1411-
`gopls` is used, because it is the fastest and works with Go modules. One
1412-
might also use `guru` for its ability to show references from other packages.
1413-
This option will be removed after `gopls` can show references from other
1414-
packages. Valid options are `gopls` and `guru`.
1410+
Use this option to define the command to be used for |:GoReferrers|. By
1411+
default `gopls` is used, because it is the fastest and works with Go modules.
1412+
One might also use `guru` for its ability to show references from other
1413+
packages. This option will be removed after `gopls` can show references from
1414+
other packages. Valid options are `gopls` and `guru`.
14151415
>
14161416
let g:go_referrers_mode = 'gopls'
14171417
<

0 commit comments

Comments
 (0)