@@ -4,16 +4,16 @@ use arrayvec::ArrayVec;
4
4
use ast:: HasName ;
5
5
use cfg:: { CfgAtom , CfgExpr } ;
6
6
use 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 ,
9
9
} ;
10
10
use ide_assists:: utils:: { has_test_related_attribute, test_related_attribute_syn} ;
11
11
use ide_db:: {
12
12
defs:: Definition ,
13
13
documentation:: docs_from_attrs,
14
14
helpers:: visit_file_defs,
15
15
search:: { FileReferenceNode , SearchScope } ,
16
- FilePosition , FxHashMap , FxHashSet , FxIndexMap , RootDatabase , SymbolKind ,
16
+ FilePosition , FxHashMap , FxIndexMap , RootDatabase , SymbolKind ,
17
17
} ;
18
18
use itertools:: Itertools ;
19
19
use smallvec:: SmallVec ;
@@ -182,20 +182,7 @@ pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> {
182
182
r
183
183
} )
184
184
} ) ) ;
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) ;
199
186
res
200
187
}
201
188
@@ -215,20 +202,38 @@ pub(crate) fn related_tests(
215
202
search_scope : Option < SearchScope > ,
216
203
) -> Vec < Runnable > {
217
204
let sema = Semantics :: new ( db) ;
218
- let mut res: FxHashSet < Runnable > = FxHashSet :: default ( ) ;
205
+ let mut res: FxIndexSet < Runnable > = FxIndexSet :: default ( ) ;
219
206
let syntax = sema. parse_guess_edition ( position. file_id ) . syntax ( ) . clone ( ) ;
220
207
221
208
find_related_tests ( & sema, & syntax, position, search_scope, & mut res) ;
222
209
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 ) )
224
229
}
225
230
226
231
fn find_related_tests (
227
232
sema : & Semantics < ' _ , RootDatabase > ,
228
233
syntax : & SyntaxNode ,
229
234
position : FilePosition ,
230
235
search_scope : Option < SearchScope > ,
231
- tests : & mut FxHashSet < Runnable > ,
236
+ tests : & mut FxIndexSet < Runnable > ,
232
237
) {
233
238
// FIXME: why is this using references::find_defs, this should use ide_db::search
234
239
let defs = match references:: find_defs ( sema, syntax, position. offset ) {
@@ -268,7 +273,7 @@ fn find_related_tests_in_module(
268
273
syntax : & SyntaxNode ,
269
274
fn_def : & ast:: Fn ,
270
275
parent_module : & hir:: Module ,
271
- tests : & mut FxHashSet < Runnable > ,
276
+ tests : & mut FxIndexSet < Runnable > ,
272
277
) {
273
278
let fn_name = match fn_def. name ( ) {
274
279
Some ( it) => it,
@@ -1501,18 +1506,18 @@ mod tests {
1501
1506
file_id: FileId(
1502
1507
0,
1503
1508
),
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 ",
1507
1512
kind: Function,
1508
1513
},
1509
1514
NavigationTarget {
1510
1515
file_id: FileId(
1511
1516
0,
1512
1517
),
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 ",
1516
1521
kind: Function,
1517
1522
},
1518
1523
]
0 commit comments