Skip to content

Commit cd6426a

Browse files
committed
Show implementations when hovering over SelfType
1 parent dcb5387 commit cd6426a

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

crates/ide/src/hover.rs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,18 @@ fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<Hov
182182
})
183183
}
184184

185-
match def {
186-
Definition::ModuleDef(it) => match it {
187-
ModuleDef::Adt(Adt::Struct(it)) => Some(to_action(it.try_to_nav(db)?)),
188-
ModuleDef::Adt(Adt::Union(it)) => Some(to_action(it.try_to_nav(db)?)),
189-
ModuleDef::Adt(Adt::Enum(it)) => Some(to_action(it.try_to_nav(db)?)),
190-
ModuleDef::Trait(it) => Some(to_action(it.try_to_nav(db)?)),
191-
_ => None,
192-
},
185+
let adt = match def {
186+
Definition::ModuleDef(ModuleDef::Trait(it)) => return it.try_to_nav(db).map(to_action),
187+
Definition::ModuleDef(ModuleDef::Adt(it)) => Some(it),
188+
Definition::SelfType(it) => it.target_ty(db).as_adt(),
193189
_ => None,
190+
}?;
191+
match adt {
192+
Adt::Struct(it) => it.try_to_nav(db),
193+
Adt::Union(it) => it.try_to_nav(db),
194+
Adt::Enum(it) => it.try_to_nav(db),
194195
}
196+
.map(to_action)
195197
}
196198

197199
fn runnable_action(
@@ -2174,6 +2176,25 @@ fn foo() { let bar = Bar; bar.fo<|>o(); }
21742176
);
21752177
}
21762178

2179+
#[test]
2180+
fn test_hover_self_has_impl_action() {
2181+
check_actions(
2182+
r#"struct foo where Self<|>:;"#,
2183+
expect![[r#"
2184+
[
2185+
Implementation(
2186+
FilePosition {
2187+
file_id: FileId(
2188+
0,
2189+
),
2190+
offset: 7,
2191+
},
2192+
),
2193+
]
2194+
"#]],
2195+
);
2196+
}
2197+
21772198
#[test]
21782199
fn test_hover_test_has_action() {
21792200
check_actions(

0 commit comments

Comments
 (0)