Show implementations when hovering over SelfType

This commit is contained in:
Lukas Wirth 2021-01-04 14:57:59 +01:00
parent dcb5387b42
commit cd6426afe5

View file

@ -182,16 +182,18 @@ fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option<Hov
})
}
match def {
Definition::ModuleDef(it) => match it {
ModuleDef::Adt(Adt::Struct(it)) => Some(to_action(it.try_to_nav(db)?)),
ModuleDef::Adt(Adt::Union(it)) => Some(to_action(it.try_to_nav(db)?)),
ModuleDef::Adt(Adt::Enum(it)) => Some(to_action(it.try_to_nav(db)?)),
ModuleDef::Trait(it) => Some(to_action(it.try_to_nav(db)?)),
_ => None,
},
let adt = match def {
Definition::ModuleDef(ModuleDef::Trait(it)) => return it.try_to_nav(db).map(to_action),
Definition::ModuleDef(ModuleDef::Adt(it)) => Some(it),
Definition::SelfType(it) => it.target_ty(db).as_adt(),
_ => None,
}?;
match adt {
Adt::Struct(it) => it.try_to_nav(db),
Adt::Union(it) => it.try_to_nav(db),
Adt::Enum(it) => it.try_to_nav(db),
}
.map(to_action)
}
fn runnable_action(
@ -2174,6 +2176,25 @@ fn foo() { let bar = Bar; bar.fo<|>o(); }
);
}
#[test]
fn test_hover_self_has_impl_action() {
check_actions(
r#"struct foo where Self<|>:;"#,
expect![[r#"
[
Implementation(
FilePosition {
file_id: FileId(
0,
),
offset: 7,
},
),
]
"#]],
);
}
#[test]
fn test_hover_test_has_action() {
check_actions(