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/hover.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'crates/ide/src/hover.rs') 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 From 5804b3fae8732576146a7da0b600b2088183dc31 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 4 Jan 2021 14:24:37 +0100 Subject: Fix HoverAction::Implementation typo --- crates/ide/src/hover.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'crates/ide/src/hover.rs') diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index e9103ce59..c0786eb51 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -70,7 +70,7 @@ impl HoverConfig { #[derive(Debug, Clone)] pub enum HoverAction { Runnable(Runnable), - Implementaion(FilePosition), + Implementation(FilePosition), GoToType(Vec), } @@ -116,12 +116,13 @@ pub(crate) fn hover( }; if let Some(definition) = definition { if let Some(markup) = hover_for_definition(db, definition) { + let markup = markup.as_str(); let markup = if !markdown { - remove_markdown(&markup.as_str()) + remove_markdown(markup) } else if links_in_hover { - rewrite_links(db, &markup.as_str(), &definition) + rewrite_links(db, markup, &definition) } else { - remove_links(&markup.as_str()) + remove_links(markup) }; res.markup = Markup::from(markup); if let Some(action) = show_implementations_action(db, definition) { @@ -175,7 +176,7 @@ pub(crate) fn hover( fn show_implementations_action(db: &RootDatabase, def: Definition) -> Option { fn to_action(nav_target: NavigationTarget) -> HoverAction { - HoverAction::Implementaion(FilePosition { + HoverAction::Implementation(FilePosition { file_id: nav_target.file_id, offset: nav_target.focus_or_full_range().start(), }) @@ -1391,7 +1392,7 @@ fn bar() { fo<|>o(); } r"unsafe trait foo<|>() {}", expect![[r#" [ - Implementaion( + Implementation( FilePosition { file_id: FileId( 0, @@ -2103,7 +2104,7 @@ fn foo() { let bar = Bar; bar.fo<|>o(); } r#"trait foo<|>() {}"#, expect![[r#" [ - Implementaion( + Implementation( FilePosition { file_id: FileId( 0, @@ -2122,7 +2123,7 @@ fn foo() { let bar = Bar; bar.fo<|>o(); } r"struct foo<|>() {}", expect![[r#" [ - Implementaion( + Implementation( FilePosition { file_id: FileId( 0, @@ -2141,7 +2142,7 @@ fn foo() { let bar = Bar; bar.fo<|>o(); } r#"union foo<|>() {}"#, expect![[r#" [ - Implementaion( + Implementation( FilePosition { file_id: FileId( 0, @@ -2160,7 +2161,7 @@ fn foo() { let bar = Bar; bar.fo<|>o(); } r"enum foo<|>() { A, B }", expect![[r#" [ - Implementaion( + Implementation( FilePosition { file_id: FileId( 0, -- cgit v1.2.3