Skip to content

Commit 325140a

Browse files
bors[bot]Veykril
andauthored
Merge #9449
9449: feat: Emit test names in `Run test` runnables if they come from a macro expansion r=matklad a=Veykril Fixes #8964 Before: ![Code_D1Tu5Iuh5I](https://user-images.githubusercontent.com/3757771/124174685-f552b380-daac-11eb-9086-c97db014b77c.png) After: ![image](https://user-images.githubusercontent.com/3757771/124174493-bb81ad00-daac-11eb-96c7-3de6545a62e1.png) Basically when a macro emits more than one test we name the test functions/modules name in the runnable instead to not emit a bunch of equally named `Run Test` annotations which don't really tell much. Note that the `Run fibonacci_test Tests` line is below the attributes due to the fact that the function name span is being reused for the generated module in rstest's expansion. Co-authored-by: Lukas Wirth <[email protected]>
2 parents 2e52d6e + f1b3446 commit 325140a

File tree

6 files changed

+362
-135
lines changed

6 files changed

+362
-135
lines changed

crates/hir/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,16 @@ impl HasVisibility for AssocItem {
16341634
}
16351635
}
16361636

1637+
impl From<AssocItem> for ModuleDef {
1638+
fn from(assoc: AssocItem) -> Self {
1639+
match assoc {
1640+
AssocItem::Function(it) => ModuleDef::Function(it),
1641+
AssocItem::Const(it) => ModuleDef::Const(it),
1642+
AssocItem::TypeAlias(it) => ModuleDef::TypeAlias(it),
1643+
}
1644+
}
1645+
}
1646+
16371647
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
16381648
pub enum GenericDef {
16391649
Function(Function),

crates/ide/src/annotations.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,22 @@ pub(crate) fn annotations(
5757
continue;
5858
}
5959

60-
let action = runnable.action();
6160
let range = runnable.nav.focus_or_full_range();
6261

62+
// dbg_runnable should go after the run annotation, to prevent a clone we do it this way
63+
let dbg_runnable = (runnable.debugee() && config.debug).then(|| Annotation {
64+
range,
65+
kind: AnnotationKind::Runnable { debug: true, runnable: runnable.clone() },
66+
});
67+
6368
if config.run {
6469
annotations.push(Annotation {
6570
range,
66-
67-
// FIXME: This one allocates without reason if run is enabled, but debug is disabled
68-
kind: AnnotationKind::Runnable { debug: false, runnable: runnable.clone() },
71+
kind: AnnotationKind::Runnable { debug: false, runnable },
6972
});
7073
}
7174

72-
if action.debugee && config.debug {
73-
annotations.push(Annotation {
74-
range,
75-
kind: AnnotationKind::Runnable { debug: true, runnable },
76-
});
77-
}
75+
annotations.extend(dbg_runnable);
7876
}
7977
}
8078

@@ -228,6 +226,7 @@ fn main() {
228226
kind: Runnable {
229227
debug: false,
230228
runnable: Runnable {
229+
use_name_in_title: false,
231230
nav: NavigationTarget {
232231
file_id: FileId(
233232
0,
@@ -247,6 +246,7 @@ fn main() {
247246
kind: Runnable {
248247
debug: true,
249248
runnable: Runnable {
249+
use_name_in_title: false,
250250
nav: NavigationTarget {
251251
file_id: FileId(
252252
0,
@@ -332,6 +332,7 @@ fn main() {
332332
kind: Runnable {
333333
debug: false,
334334
runnable: Runnable {
335+
use_name_in_title: false,
335336
nav: NavigationTarget {
336337
file_id: FileId(
337338
0,
@@ -351,6 +352,7 @@ fn main() {
351352
kind: Runnable {
352353
debug: true,
353354
runnable: Runnable {
355+
use_name_in_title: false,
354356
nav: NavigationTarget {
355357
file_id: FileId(
356358
0,
@@ -440,6 +442,7 @@ fn main() {
440442
kind: Runnable {
441443
debug: false,
442444
runnable: Runnable {
445+
use_name_in_title: false,
443446
nav: NavigationTarget {
444447
file_id: FileId(
445448
0,
@@ -459,6 +462,7 @@ fn main() {
459462
kind: Runnable {
460463
debug: true,
461464
runnable: Runnable {
465+
use_name_in_title: false,
462466
nav: NavigationTarget {
463467
file_id: FileId(
464468
0,
@@ -601,6 +605,7 @@ fn main() {}
601605
kind: Runnable {
602606
debug: false,
603607
runnable: Runnable {
608+
use_name_in_title: false,
604609
nav: NavigationTarget {
605610
file_id: FileId(
606611
0,
@@ -620,6 +625,7 @@ fn main() {}
620625
kind: Runnable {
621626
debug: true,
622627
runnable: Runnable {
628+
use_name_in_title: false,
623629
nav: NavigationTarget {
624630
file_id: FileId(
625631
0,
@@ -674,6 +680,7 @@ fn main() {
674680
kind: Runnable {
675681
debug: false,
676682
runnable: Runnable {
683+
use_name_in_title: false,
677684
nav: NavigationTarget {
678685
file_id: FileId(
679686
0,
@@ -693,6 +700,7 @@ fn main() {
693700
kind: Runnable {
694701
debug: true,
695702
runnable: Runnable {
703+
use_name_in_title: false,
696704
nav: NavigationTarget {
697705
file_id: FileId(
698706
0,
@@ -816,6 +824,7 @@ mod tests {
816824
kind: Runnable {
817825
debug: false,
818826
runnable: Runnable {
827+
use_name_in_title: false,
819828
nav: NavigationTarget {
820829
file_id: FileId(
821830
0,
@@ -835,6 +844,7 @@ mod tests {
835844
kind: Runnable {
836845
debug: true,
837846
runnable: Runnable {
847+
use_name_in_title: false,
838848
nav: NavigationTarget {
839849
file_id: FileId(
840850
0,
@@ -854,6 +864,7 @@ mod tests {
854864
kind: Runnable {
855865
debug: false,
856866
runnable: Runnable {
867+
use_name_in_title: false,
857868
nav: NavigationTarget {
858869
file_id: FileId(
859870
0,
@@ -876,6 +887,7 @@ mod tests {
876887
kind: Runnable {
877888
debug: true,
878889
runnable: Runnable {
890+
use_name_in_title: false,
879891
nav: NavigationTarget {
880892
file_id: FileId(
881893
0,
@@ -898,6 +910,7 @@ mod tests {
898910
kind: Runnable {
899911
debug: false,
900912
runnable: Runnable {
913+
use_name_in_title: false,
901914
nav: NavigationTarget {
902915
file_id: FileId(
903916
0,
@@ -924,6 +937,7 @@ mod tests {
924937
kind: Runnable {
925938
debug: true,
926939
runnable: Runnable {
940+
use_name_in_title: false,
927941
nav: NavigationTarget {
928942
file_id: FileId(
929943
0,

crates/ide/src/hover.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,6 +2463,7 @@ fn foo_$0test() {}
24632463
),
24642464
Runnable(
24652465
Runnable {
2466+
use_name_in_title: false,
24662467
nav: NavigationTarget {
24672468
file_id: FileId(
24682469
0,
@@ -2501,6 +2502,7 @@ mod tests$0 {
25012502
[
25022503
Runnable(
25032504
Runnable {
2505+
use_name_in_title: false,
25042506
nav: NavigationTarget {
25052507
file_id: FileId(
25062508
0,

0 commit comments

Comments
 (0)