aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-01-04 13:57:59 +0000
committerLukas Wirth <[email protected]>2021-01-04 13:57:59 +0000
commitcd6426afe5daaeb90c4398669bcae03a6c353658 (patch)
tree9f5317661ae0d3035bde9c170ddb74652ea92589 /crates
parentdcb5387b420456d6cb827a90756931ada70f4e6a (diff)
Show implementations when hovering over SelfType
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/hover.rs37
1 files changed, 29 insertions, 8 deletions
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<Hov
182 }) 182 })
183 } 183 }
184 184
185 match def { 185 let adt = match def {
186 Definition::ModuleDef(it) => match it { 186 Definition::ModuleDef(ModuleDef::Trait(it)) => return it.try_to_nav(db).map(to_action),
187 ModuleDef::Adt(Adt::Struct(it)) => Some(to_action(it.try_to_nav(db)?)), 187 Definition::ModuleDef(ModuleDef::Adt(it)) => Some(it),
188 ModuleDef::Adt(Adt::Union(it)) => Some(to_action(it.try_to_nav(db)?)), 188 Definition::SelfType(it) => it.target_ty(db).as_adt(),
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 },
193 _ => None, 189 _ => 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),
194 } 195 }
196 .map(to_action)
195} 197}
196 198
197fn runnable_action( 199fn runnable_action(
@@ -2175,6 +2177,25 @@ fn foo() { let bar = Bar; bar.fo<|>o(); }
2175 } 2177 }
2176 2178
2177 #[test] 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
2198 #[test]
2178 fn test_hover_test_has_action() { 2199 fn test_hover_test_has_action() {
2179 check_actions( 2200 check_actions(
2180 r#" 2201 r#"