@@ -4,16 +4,16 @@ use arrayvec::ArrayVec;
44use ast:: HasName ;
55use cfg:: { CfgAtom , CfgExpr } ;
66use hir:: {
7- db:: HirDatabase , sym, AsAssocItem , AttrsWithOwner , HasAttrs , HasCrate , HasSource , HirFileIdExt ,
8- ModPath , Name , PathKind , Semantics , Symbol ,
7+ db:: HirDatabase , sym, symbols :: FxIndexSet , AsAssocItem , AttrsWithOwner , HasAttrs , HasCrate ,
8+ HasSource , HirFileIdExt , ModPath , Name , PathKind , Semantics , Symbol ,
99} ;
1010use ide_assists:: utils:: { has_test_related_attribute, test_related_attribute_syn} ;
1111use ide_db:: {
1212 defs:: Definition ,
1313 documentation:: docs_from_attrs,
1414 helpers:: visit_file_defs,
1515 search:: { FileReferenceNode , SearchScope } ,
16- FilePosition , FxHashMap , FxHashSet , FxIndexMap , RootDatabase , SymbolKind ,
16+ FilePosition , FxHashMap , FxIndexMap , RootDatabase , SymbolKind ,
1717} ;
1818use itertools:: Itertools ;
1919use smallvec:: SmallVec ;
@@ -182,20 +182,7 @@ pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> {
182182 r
183183 } )
184184 } ) ) ;
185- res. sort_by ( |Runnable { nav, kind, .. } , Runnable { nav : nav_b, kind : kind_b, .. } | {
186- // full_range.start < focus_range.start < name, should give us a decent unique ordering
187- nav. full_range
188- . start ( )
189- . cmp ( & nav_b. full_range . start ( ) )
190- . then_with ( || {
191- let t_0 = || TextSize :: from ( 0 ) ;
192- nav. focus_range
193- . map_or_else ( t_0, |it| it. start ( ) )
194- . cmp ( & nav_b. focus_range . map_or_else ( t_0, |it| it. start ( ) ) )
195- } )
196- . then_with ( || kind. disc ( ) . cmp ( & kind_b. disc ( ) ) )
197- . then_with ( || nav. name . cmp ( & nav_b. name ) )
198- } ) ;
185+ res. sort_by ( cmp_runnables) ;
199186 res
200187}
201188
@@ -215,20 +202,38 @@ pub(crate) fn related_tests(
215202 search_scope : Option < SearchScope > ,
216203) -> Vec < Runnable > {
217204 let sema = Semantics :: new ( db) ;
218- let mut res: FxHashSet < Runnable > = FxHashSet :: default ( ) ;
205+ let mut res: FxIndexSet < Runnable > = FxIndexSet :: default ( ) ;
219206 let syntax = sema. parse_guess_edition ( position. file_id ) . syntax ( ) . clone ( ) ;
220207
221208 find_related_tests ( & sema, & syntax, position, search_scope, & mut res) ;
222209
223- res. into_iter ( ) . collect ( )
210+ res. into_iter ( ) . sorted_by ( cmp_runnables) . collect ( )
211+ }
212+
213+ fn cmp_runnables (
214+ Runnable { nav, kind, .. } : & Runnable ,
215+ Runnable { nav : nav_b, kind : kind_b, .. } : & Runnable ,
216+ ) -> std:: cmp:: Ordering {
217+ // full_range.start < focus_range.start < name, should give us a decent unique ordering
218+ nav. full_range
219+ . start ( )
220+ . cmp ( & nav_b. full_range . start ( ) )
221+ . then_with ( || {
222+ let t_0 = || TextSize :: from ( 0 ) ;
223+ nav. focus_range
224+ . map_or_else ( t_0, |it| it. start ( ) )
225+ . cmp ( & nav_b. focus_range . map_or_else ( t_0, |it| it. start ( ) ) )
226+ } )
227+ . then_with ( || kind. disc ( ) . cmp ( & kind_b. disc ( ) ) )
228+ . then_with ( || nav. name . cmp ( & nav_b. name ) )
224229}
225230
226231fn find_related_tests (
227232 sema : & Semantics < ' _ , RootDatabase > ,
228233 syntax : & SyntaxNode ,
229234 position : FilePosition ,
230235 search_scope : Option < SearchScope > ,
231- tests : & mut FxHashSet < Runnable > ,
236+ tests : & mut FxIndexSet < Runnable > ,
232237) {
233238 // FIXME: why is this using references::find_defs, this should use ide_db::search
234239 let defs = match references:: find_defs ( sema, syntax, position. offset ) {
@@ -268,7 +273,7 @@ fn find_related_tests_in_module(
268273 syntax : & SyntaxNode ,
269274 fn_def : & ast:: Fn ,
270275 parent_module : & hir:: Module ,
271- tests : & mut FxHashSet < Runnable > ,
276+ tests : & mut FxIndexSet < Runnable > ,
272277) {
273278 let fn_name = match fn_def. name ( ) {
274279 Some ( it) => it,
@@ -1501,18 +1506,18 @@ mod tests {
15011506 file_id: FileId(
15021507 0,
15031508 ),
1504- full_range: 121..185 ,
1505- focus_range: 136..145 ,
1506- name: "foo2_test ",
1509+ full_range: 52..115 ,
1510+ focus_range: 67..75 ,
1511+ name: "foo_test ",
15071512 kind: Function,
15081513 },
15091514 NavigationTarget {
15101515 file_id: FileId(
15111516 0,
15121517 ),
1513- full_range: 52..115 ,
1514- focus_range: 67..75 ,
1515- name: "foo_test ",
1518+ full_range: 121..185 ,
1519+ focus_range: 136..145 ,
1520+ name: "foo2_test ",
15161521 kind: Function,
15171522 },
15181523 ]
0 commit comments