aboutsummaryrefslogtreecommitdiff
path: root/crates/ide
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-01-01 23:05:51 +0000
committerLukas Wirth <[email protected]>2021-01-04 11:24:47 +0000
commit47900dd3bc1cca74e06a3ac1f587e92e352fbd42 (patch)
tree61bbf0f03da85b42229a103203d5840fbbba3048 /crates/ide
parent5b86ff3e91838e58397ec39502d85056e46fcfcb (diff)
Impl hovering for TypeParams
Diffstat (limited to 'crates/ide')
-rw-r--r--crates/ide/src/hover.rs52
1 files changed, 50 insertions, 2 deletions
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs
index 2737c900f..61439ae53 100644
--- a/crates/ide/src/hover.rs
+++ b/crates/ide/src/hover.rs
@@ -370,8 +370,9 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
370 } 370 }
371 Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))), 371 Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
372 Definition::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))), 372 Definition::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))),
373 Definition::TypeParam(_) | Definition::ConstParam(_) => { 373 Definition::TypeParam(type_param) => Some(Markup::fenced_block(&type_param.display(db))),
374 // FIXME: Hover for generic param 374 Definition::ConstParam(_) => {
375 // FIXME: Hover for generic const param
375 None 376 None
376 } 377 }
377 }; 378 };
@@ -3257,4 +3258,51 @@ fn foo() {
3257 "#]], 3258 "#]],
3258 ); 3259 );
3259 } 3260 }
3261
3262 #[test]
3263 fn hover_type_param() {
3264 check(
3265 r#"
3266struct Foo<T>(T);
3267trait Copy {}
3268trait Clone {}
3269trait Sized {}
3270impl<T: Copy + Clone> Foo<T<|>> where T: Sized {}
3271"#,
3272 expect![[r#"
3273 *T*
3274
3275 ```rust
3276 T: Copy + Clone + Sized
3277 ```
3278 "#]],
3279 );
3280 check(
3281 r#"
3282struct Foo<T>(T);
3283impl<T> Foo<T<|>> {}
3284"#,
3285 expect![[r#"
3286 *T*
3287
3288 ```rust
3289 T
3290 ```
3291 "#]],
3292 );
3293 // lifetimes aren't being substituted yet
3294 check(
3295 r#"
3296struct Foo<T>(T);
3297impl<T: 'static> Foo<T<|>> {}
3298"#,
3299 expect![[r#"
3300 *T*
3301
3302 ```rust
3303 T: {error}
3304 ```
3305 "#]],
3306 );
3307 }
3260} 3308}