From 0ae0909a1676903baf33999d5f23d51fb838111b Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 4 Jan 2021 14:18:31 +0100 Subject: Implement hover for ConstParam --- crates/ide/src/display/short_label.rs | 11 +++++++++++ crates/ide/src/hover.rs | 22 ++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) (limited to 'crates/ide') diff --git a/crates/ide/src/display/short_label.rs b/crates/ide/src/display/short_label.rs index ea49d9f97..990f740b8 100644 --- a/crates/ide/src/display/short_label.rs +++ b/crates/ide/src/display/short_label.rs @@ -87,6 +87,17 @@ impl ShortLabel for ast::Variant { } } +impl ShortLabel for ast::ConstParam { + fn short_label(&self) -> Option { + let mut buf = "const ".to_owned(); + buf.push_str(self.name()?.text().as_str()); + if let Some(type_ref) = self.ty() { + format_to!(buf, ": {}", type_ref.syntax()); + } + Some(buf) + } +} + fn short_label_from_ty(node: &T, ty: Option, prefix: &str) -> Option where T: NameOwner + VisibilityOwner, diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 61439ae53..e9103ce59 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -371,10 +371,7 @@ 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(type_param) => Some(Markup::fenced_block(&type_param.display(db))), - Definition::ConstParam(_) => { - // FIXME: Hover for generic const param - None - } + Definition::ConstParam(it) => from_def_source(db, it, None), }; fn from_def_source(db: &RootDatabase, def: D, mod_path: Option) -> Option @@ -3305,4 +3302,21 @@ impl Foo> {} "#]], ); } + + #[test] + fn hover_const_param() { + check( + r#" +struct Foo; +impl Foo> {} +"#, + expect![[r#" + *LEN* + + ```rust + const LEN: usize + ``` + "#]], + ); + } } -- cgit v1.2.3