Impl hovering for TypeParams

This commit is contained in:
Lukas Wirth 2021-01-02 00:05:51 +01:00
parent 5b86ff3e91
commit 47900dd3bc
3 changed files with 67 additions and 7 deletions

View file

@ -370,8 +370,9 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
}
Definition::Label(it) => Some(Markup::fenced_block(&it.name(db))),
Definition::LifetimeParam(it) => Some(Markup::fenced_block(&it.name(db))),
Definition::TypeParam(_) | Definition::ConstParam(_) => {
// FIXME: Hover for generic param
Definition::TypeParam(type_param) => Some(Markup::fenced_block(&type_param.display(db))),
Definition::ConstParam(_) => {
// FIXME: Hover for generic const param
None
}
};
@ -3257,4 +3258,51 @@ fn foo() {
"#]],
);
}
#[test]
fn hover_type_param() {
check(
r#"
struct Foo<T>(T);
trait Copy {}
trait Clone {}
trait Sized {}
impl<T: Copy + Clone> Foo<T<|>> where T: Sized {}
"#,
expect![[r#"
*T*
```rust
T: Copy + Clone + Sized
```
"#]],
);
check(
r#"
struct Foo<T>(T);
impl<T> Foo<T<|>> {}
"#,
expect![[r#"
*T*
```rust
T
```
"#]],
);
// lifetimes aren't being substituted yet
check(
r#"
struct Foo<T>(T);
impl<T: 'static> Foo<T<|>> {}
"#,
expect![[r#"
*T*
```rust
T: {error}
```
"#]],
);
}
}