From cd6426afe5daaeb90c4398669bcae03a6c353658 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 4 Jan 2021 14:57:59 +0100 Subject: Show implementations when hovering over SelfType --- crates/ide/src/hover.rs | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'crates/ide') diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index c0786eb51..399e3e484 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -182,16 +182,18 @@ fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option 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( -- cgit v1.2.3