@@ -15,6 +15,7 @@ use ide_db::{
15
15
FxHashMap , FxHashSet , RootDatabase , SymbolKind ,
16
16
} ;
17
17
use itertools:: Itertools ;
18
+ use span:: TextSize ;
18
19
use stdx:: { always, format_to} ;
19
20
use syntax:: {
20
21
ast:: { self , AstNode } ,
@@ -48,23 +49,34 @@ impl fmt::Display for TestId {
48
49
49
50
#[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
50
51
pub enum RunnableKind {
51
- Test { test_id : TestId , attr : TestAttr } ,
52
52
TestMod { path : String } ,
53
+ Test { test_id : TestId , attr : TestAttr } ,
53
54
Bench { test_id : TestId } ,
54
55
DocTest { test_id : TestId } ,
55
56
Bin ,
56
57
}
57
58
58
- #[ cfg( test) ]
59
- #[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
60
- enum RunnableTestKind {
59
+ #[ derive( Debug , Clone , Hash , PartialEq , Eq , PartialOrd , Ord ) ]
60
+ enum RunnableDiscKind {
61
61
Test ,
62
62
TestMod ,
63
63
DocTest ,
64
64
Bench ,
65
65
Bin ,
66
66
}
67
67
68
+ impl RunnableKind {
69
+ fn disc ( & self ) -> RunnableDiscKind {
70
+ match self {
71
+ RunnableKind :: TestMod { .. } => RunnableDiscKind :: TestMod ,
72
+ RunnableKind :: Test { .. } => RunnableDiscKind :: Test ,
73
+ RunnableKind :: DocTest { .. } => RunnableDiscKind :: DocTest ,
74
+ RunnableKind :: Bench { .. } => RunnableDiscKind :: Bench ,
75
+ RunnableKind :: Bin => RunnableDiscKind :: Bin ,
76
+ }
77
+ }
78
+ }
79
+
68
80
impl Runnable {
69
81
// test package::module::testname
70
82
pub fn label ( & self , target : Option < String > ) -> String {
@@ -97,17 +109,6 @@ impl Runnable {
97
109
s. push_str ( suffix) ;
98
110
s
99
111
}
100
-
101
- #[ cfg( test) ]
102
- fn test_kind ( & self ) -> RunnableTestKind {
103
- match & self . kind {
104
- RunnableKind :: TestMod { .. } => RunnableTestKind :: TestMod ,
105
- RunnableKind :: Test { .. } => RunnableTestKind :: Test ,
106
- RunnableKind :: DocTest { .. } => RunnableTestKind :: DocTest ,
107
- RunnableKind :: Bench { .. } => RunnableTestKind :: Bench ,
108
- RunnableKind :: Bin => RunnableTestKind :: Bin ,
109
- }
110
- }
111
112
}
112
113
113
114
// Feature: Run
@@ -193,6 +194,20 @@ pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> {
193
194
r
194
195
} )
195
196
} ) ) ;
197
+ res. sort_by ( |Runnable { nav, kind, .. } , Runnable { nav : nav_b, kind : kind_b, .. } | {
198
+ // full_range.start < focus_range.start < name, should give us a decent unique ordering
199
+ nav. full_range
200
+ . start ( )
201
+ . cmp ( & nav_b. full_range . start ( ) )
202
+ . then_with ( || {
203
+ let t_0 = || TextSize :: from ( 0 ) ;
204
+ nav. focus_range
205
+ . map_or_else ( t_0, |it| it. start ( ) )
206
+ . cmp ( & nav_b. focus_range . map_or_else ( t_0, |it| it. start ( ) ) )
207
+ } )
208
+ . then_with ( || kind. disc ( ) . cmp ( & kind_b. disc ( ) ) )
209
+ . then_with ( || nav. name . cmp ( & nav_b. name ) )
210
+ } ) ;
196
211
res
197
212
}
198
213
@@ -571,13 +586,12 @@ mod tests {
571
586
572
587
fn check ( ra_fixture : & str , expect : Expect ) {
573
588
let ( analysis, position) = fixture:: position ( ra_fixture) ;
574
- let mut runnables = analysis. runnables ( position. file_id ) . unwrap ( ) ;
575
- runnables. sort_by_key ( |it| ( it. nav . full_range . start ( ) , it. nav . name . clone ( ) ) ) ;
576
-
577
- let result = runnables
589
+ let result = analysis
590
+ . runnables ( position. file_id )
591
+ . unwrap ( )
578
592
. into_iter ( )
579
593
. map ( |runnable| {
580
- let mut a = format ! ( "({:?}, {:?}" , runnable. test_kind ( ) , runnable. nav) ;
594
+ let mut a = format ! ( "({:?}, {:?}" , runnable. kind . disc ( ) , runnable. nav) ;
581
595
if runnable. use_name_in_title {
582
596
a. push_str ( ", true" ) ;
583
597
}
0 commit comments