1+ use either:: Either ;
12use hir:: {
23 Adt , AsAssocItem , AssocItemContainer , FieldSource , GenericParam , HasAttrs , HasSource ,
34 HirDisplay , Module , ModuleDef , ModuleSource , Semantics ,
@@ -366,7 +367,7 @@ fn hover_for_definition(
366367 . and_then ( |fd| hover_for_builtin ( fd, it) )
367368 . or_else ( || Some ( Markup :: fenced_block ( & it. name ( ) ) ) ) ,
368369 } ,
369- Definition :: Local ( it) => Some ( Markup :: fenced_block ( & it . ty ( db ) . display ( db ) ) ) ,
370+ Definition :: Local ( it) => hover_for_local ( it , db ) ,
370371 Definition :: SelfType ( impl_def) => {
371372 impl_def. target_ty ( db) . as_adt ( ) . and_then ( |adt| match adt {
372373 Adt :: Struct ( it) => from_def_source ( db, it, mod_path) ,
@@ -405,6 +406,29 @@ fn hover_for_definition(
405406 }
406407}
407408
409+ fn hover_for_local ( it : hir:: Local , db : & RootDatabase ) -> Option < Markup > {
410+ let ty = it. ty ( db) ;
411+ let ty = ty. display ( db) ;
412+ let is_mut = if it. is_mut ( db) { "mut " } else { "" } ;
413+ let desc = match it. source ( db) . value {
414+ Either :: Left ( ident) => {
415+ let name = it. name ( db) . unwrap ( ) ;
416+ let let_kw = if ident
417+ . syntax ( )
418+ . parent ( )
419+ . map_or ( false , |p| p. kind ( ) == LET_STMT || p. kind ( ) == CONDITION )
420+ {
421+ "let "
422+ } else {
423+ ""
424+ } ;
425+ format ! ( "{}{}{}: {}" , let_kw, is_mut, name, ty)
426+ }
427+ Either :: Right ( _) => format ! ( "{}self: {}" , is_mut, ty) ,
428+ } ;
429+ hover_markup ( None , Some ( desc) , None )
430+ }
431+
408432fn hover_for_keyword (
409433 sema : & Semantics < RootDatabase > ,
410434 links_in_hover : bool ,
@@ -574,7 +598,7 @@ fn main() {
574598 *iter*
575599
576600 ```rust
577- Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
601+ let mut iter: Iter<Scan<OtherStruct<OtherStruct<i32>>, |&mut u32, &u32, &mut u32| -> Option<u32>, u32>>
578602 ```
579603 "# ] ] ,
580604 ) ;
@@ -798,7 +822,7 @@ fn main() {
798822 ```
799823
800824 ```rust
801- const foo: u32 = 123
825+ const foo: u32
802826 ```
803827 "# ] ] ,
804828 ) ;
@@ -831,7 +855,7 @@ fn main() {
831855 *zz*
832856
833857 ```rust
834- Test<i32, u8>
858+ let zz: Test<i32, u8>
835859 ```
836860 "# ] ] ,
837861 ) ;
@@ -870,7 +894,7 @@ fn main() { let b$0ar = Some(12); }
870894 *bar*
871895
872896 ```rust
873- Option<i32>
897+ let bar: Option<i32>
874898 ```
875899 "# ] ] ,
876900 ) ;
@@ -938,7 +962,7 @@ fn main() {
938962 *foo*
939963
940964 ```rust
941- i32
965+ foo: i32
942966 ```
943967 "# ] ] ,
944968 )
@@ -952,7 +976,7 @@ fn main() {
952976 *foo*
953977
954978 ```rust
955- i32
979+ foo: i32
956980 ```
957981 "# ] ] ,
958982 )
@@ -966,7 +990,7 @@ fn main() {
966990 *foo*
967991
968992 ```rust
969- i32
993+ foo: i32
970994 ```
971995 "# ] ] ,
972996 )
@@ -980,7 +1004,7 @@ fn main() {
9801004 *foo*
9811005
9821006 ```rust
983- i32
1007+ foo: i32
9841008 ```
9851009 "# ] ] ,
9861010 )
@@ -1000,7 +1024,7 @@ fn main() {
10001024 *_x*
10011025
10021026 ```rust
1003- impl Deref<Target = u8> + DerefMut<Target = u8>
1027+ _x: impl Deref<Target = u8> + DerefMut<Target = u8>
10041028 ```
10051029 "# ] ] ,
10061030 )
@@ -1022,7 +1046,7 @@ fn main() { let foo_$0test = Thing::new(); }
10221046 *foo_test*
10231047
10241048 ```rust
1025- Thing
1049+ let foo_test: Thing
10261050 ```
10271051 "# ] ] ,
10281052 )
@@ -1081,7 +1105,7 @@ fn main() {
10811105 ```
10821106
10831107 ```rust
1084- const C: u32 = 1
1108+ const C: u32
10851109 ```
10861110 "# ] ] ,
10871111 )
@@ -1182,7 +1206,7 @@ fn y() {
11821206 *x*
11831207
11841208 ```rust
1185- i32
1209+ let x: i32
11861210 ```
11871211 "# ] ] ,
11881212 )
@@ -1259,7 +1283,7 @@ fn foo(bar:u32) { let a = id!(ba$0r); }
12591283 *bar*
12601284
12611285 ```rust
1262- u32
1286+ bar: u32
12631287 ```
12641288 "# ] ] ,
12651289 ) ;
@@ -1277,7 +1301,7 @@ fn foo(bar:u32) { let a = id!(ba$0r); }
12771301 *bar*
12781302
12791303 ```rust
1280- u32
1304+ bar: u32
12811305 ```
12821306 "# ] ] ,
12831307 ) ;
@@ -3302,7 +3326,7 @@ fn main() {
33023326 *f*
33033327
33043328 ```rust
3305- &i32
3329+ f: &i32
33063330 ```
33073331 "# ] ] ,
33083332 ) ;
@@ -3321,7 +3345,7 @@ impl Foo {
33213345 *self*
33223346
33233347 ```rust
3324- &Foo
3348+ self: &Foo
33253349 ```
33263350 "# ] ] ,
33273351 ) ;
@@ -3341,7 +3365,7 @@ impl Foo {
33413365 *self*
33423366
33433367 ```rust
3344- Arc<Foo>
3368+ self: Arc<Foo>
33453369 ```
33463370 "# ] ] ,
33473371 ) ;
@@ -3537,7 +3561,7 @@ fn foo() {
35373561 ```
35383562
35393563 ```rust
3540- const FOO: usize = 3
3564+ const FOO: usize
35413565 ```
35423566
35433567 ---
0 commit comments