mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +00:00
Show implementations when hovering over SelfType
This commit is contained in:
parent
dcb5387b42
commit
cd6426afe5
1 changed files with 29 additions and 8 deletions
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue