aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/hover.rs119
1 files changed, 74 insertions, 45 deletions
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs
index 94ad800a0..462f5c2b8 100644
--- a/crates/ide/src/hover.rs
+++ b/crates/ide/src/hover.rs
@@ -295,7 +295,6 @@ fn definition_owner_name(db: &RootDatabase, def: &Definition) -> Option<String>
295 ModuleDef::EnumVariant(e) => Some(e.parent_enum(db).name(db)), 295 ModuleDef::EnumVariant(e) => Some(e.parent_enum(db).name(db)),
296 _ => None, 296 _ => None,
297 }, 297 },
298 Definition::SelfType(i) => i.target_ty(db).as_adt().map(|adt| adt.name(db)),
299 _ => None, 298 _ => None,
300 } 299 }
301 .map(|name| name.to_string()) 300 .map(|name| name.to_string())
@@ -357,7 +356,14 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
357 ModuleDef::BuiltinType(it) => return Some(it.to_string().into()), 356 ModuleDef::BuiltinType(it) => return Some(it.to_string().into()),
358 }, 357 },
359 Definition::Local(it) => return Some(Markup::fenced_block(&it.ty(db).display(db))), 358 Definition::Local(it) => return Some(Markup::fenced_block(&it.ty(db).display(db))),
360 Definition::TypeParam(_) | Definition::SelfType(_) => { 359 Definition::SelfType(impl_def) => {
360 impl_def.target_ty(db).as_adt().and_then(|adt| match adt {
361 Adt::Struct(it) => from_def_source(db, it, mod_path),
362 Adt::Union(it) => from_def_source(db, it, mod_path),
363 Adt::Enum(it) => from_def_source(db, it, mod_path),
364 })
365 }
366 Definition::TypeParam(_) => {
361 // FIXME: Hover for generic param 367 // FIXME: Hover for generic param
362 None 368 None
363 } 369 }
@@ -1025,52 +1031,75 @@ impl Thing {
1025} 1031}
1026"#, 1032"#,
1027 expect![[r#" 1033 expect![[r#"
1028 *Self { x: 0 }* 1034 *Self*
1035
1029 ```rust 1036 ```rust
1030 Thing 1037 test
1038 ```
1039
1040 ```rust
1041 struct Thing
1031 ``` 1042 ```
1032 "#]], 1043 "#]],
1033 ) 1044 );
1034 } /* FIXME: revive these tests 1045 check(
1035 let (analysis, position) = fixture::position( 1046 r#"
1036 " 1047struct Thing { x: u32 }
1037 struct Thing { x: u32 } 1048impl Thing {
1038 impl Thing { 1049 fn new() -> Self<|> { Self { x: 0 } }
1039 fn new() -> Self<|> { 1050}
1040 Self { x: 0 } 1051"#,
1041 } 1052 expect![[r#"
1042 } 1053 *Self*
1043 ", 1054
1044 ); 1055 ```rust
1045 1056 test
1046 let hover = analysis.hover(position).unwrap().unwrap(); 1057 ```
1047 assert_eq!(trim_markup(&hover.info.markup.as_str()), ("Thing")); 1058
1048 1059 ```rust
1049 let (analysis, position) = fixture::position( 1060 struct Thing
1050 " 1061 ```
1051 enum Thing { A } 1062 "#]],
1052 impl Thing { 1063 );
1053 pub fn new() -> Self<|> { 1064 check(
1054 Thing::A 1065 r#"
1055 } 1066enum Thing { A }
1056 } 1067impl Thing {
1057 ", 1068 pub fn new() -> Self<|> { Thing::A }
1058 ); 1069}
1059 let hover = analysis.hover(position).unwrap().unwrap(); 1070"#,
1060 assert_eq!(trim_markup(&hover.info.markup.as_str()), ("enum Thing")); 1071 expect![[r#"
1061 1072 *Self*
1062 let (analysis, position) = fixture::position( 1073
1063 " 1074 ```rust
1064 enum Thing { A } 1075 test
1065 impl Thing { 1076 ```
1066 pub fn thing(a: Self<|>) { 1077
1067 } 1078 ```rust
1068 } 1079 enum Thing
1069 ", 1080 ```
1070 ); 1081 "#]],
1071 let hover = analysis.hover(position).unwrap().unwrap(); 1082 );
1072 assert_eq!(trim_markup(&hover.info.markup.as_str()), ("enum Thing")); 1083 check(
1073 */ 1084 r#"
1085 enum Thing { A }
1086 impl Thing {
1087 pub fn thing(a: Self<|>) {}
1088 }
1089 "#,
1090 expect![[r#"
1091 *Self*
1092
1093 ```rust
1094 test
1095 ```
1096
1097 ```rust
1098 enum Thing
1099 ```
1100 "#]],
1101 );
1102 }
1074 1103
1075 #[test] 1104 #[test]
1076 fn test_hover_shadowing_pat() { 1105 fn test_hover_shadowing_pat() {