From 47900dd3bc1cca74e06a3ac1f587e92e352fbd42 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sat, 2 Jan 2021 00:05:51 +0100 Subject: Impl hovering for TypeParams --- crates/ide/src/hover.rs | 52 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) (limited to 'crates/ide') 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 { } 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); +trait Copy {} +trait Clone {} +trait Sized {} +impl Foo> where T: Sized {} +"#, + expect![[r#" + *T* + + ```rust + T: Copy + Clone + Sized + ``` + "#]], + ); + check( + r#" +struct Foo(T); +impl Foo> {} +"#, + expect![[r#" + *T* + + ```rust + T + ``` + "#]], + ); + // lifetimes aren't being substituted yet + check( + r#" +struct Foo(T); +impl Foo> {} +"#, + expect![[r#" + *T* + + ```rust + T: {error} + ``` + "#]], + ); + } } -- cgit v1.2.3