File tree 2 files changed +42
-1
lines changed
2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -1189,7 +1189,18 @@ impl HirDisplay for Path {
1189
1189
write ! ( f, "super" ) ?;
1190
1190
}
1191
1191
}
1192
- ( _, PathKind :: DollarCrate ( _) ) => write ! ( f, "{{extern_crate}}" ) ?,
1192
+ ( _, PathKind :: DollarCrate ( id) ) => {
1193
+ // Resolve `$crate` to the crate's display name.
1194
+ // FIXME: should use the dependency name instead if available, but that depends on
1195
+ // the crate invoking `HirDisplay`
1196
+ let crate_graph = f. db . crate_graph ( ) ;
1197
+ let name = crate_graph[ * id]
1198
+ . display_name
1199
+ . as_ref ( )
1200
+ . map ( |name| name. canonical_name ( ) )
1201
+ . unwrap_or ( "$crate" ) ;
1202
+ write ! ( f, "{name}" ) ?
1203
+ }
1193
1204
}
1194
1205
1195
1206
for ( seg_idx, segment) in self . segments ( ) . iter ( ) . enumerate ( ) {
Original file line number Diff line number Diff line change @@ -4583,3 +4583,33 @@ pub struct Foo;
4583
4583
"## ] ] ,
4584
4584
) ;
4585
4585
}
4586
+
4587
+ #[ test]
4588
+ fn hover_dollar_crate ( ) {
4589
+ // $crate should be resolved to the right crate name.
4590
+
4591
+ check (
4592
+ r#"
4593
+ //- /main.rs crate:main deps:dep
4594
+ dep::m!(KONST$0);
4595
+ //- /dep.rs crate:dep
4596
+ #[macro_export]
4597
+ macro_rules! m {
4598
+ ( $name:ident ) => { const $name: $crate::Type = $crate::Type; };
4599
+ }
4600
+
4601
+ pub struct Type;
4602
+ "# ,
4603
+ expect ! [ [ r#"
4604
+ *KONST*
4605
+
4606
+ ```rust
4607
+ main
4608
+ ```
4609
+
4610
+ ```rust
4611
+ const KONST: dep::Type = $crate::Type
4612
+ ```
4613
+ "# ] ] ,
4614
+ ) ;
4615
+ }
You can’t perform that action at this time.
0 commit comments