From 5c0556c2caa2e896d20ab47f87dc88121eda8261 Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Thu, 7 Mar 2019 20:28:51 +0200 Subject: Fix EnumVariants not showing properly when hovering This fixes documentation as well for EnumVariants --- crates/ra_ide_api/src/hover.rs | 58 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index f14001e84..1c7d1f3fd 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -195,6 +195,7 @@ impl NavigationTarget { .visit(doc_comments::) .visit(doc_comments::) .visit(doc_comments::) + .visit(doc_comments::) .accept(&node)? } @@ -240,6 +241,7 @@ impl NavigationTarget { .visit(|node: &ast::ConstDef| visit_ascribed_node(node, "const ")) .visit(|node: &ast::StaticDef| visit_ascribed_node(node, "static ")) .visit(|node: &ast::NamedFieldDef| visit_ascribed_node(node, "")) + .visit(|node: &ast::EnumVariant| Some(node.name()?.syntax().text().to_string())) .accept(&node)? } } @@ -428,8 +430,60 @@ mod tests { ", ); let hover = analysis.hover(position).unwrap().unwrap(); - // not the nicest way to show it currently - assert_eq!(trim_markup_opt(hover.info.first()), Some("Some(T) -> Option")); + assert_eq!(trim_markup_opt(hover.info.first()), Some("Some")); + + let (analysis, position) = single_file_with_position( + " + enum Option { Some(T) } + use Option::Some; + + fn main() { + let b<|>ar = Some(12); + } + ", + ); + let hover = analysis.hover(position).unwrap().unwrap(); + assert_eq!(trim_markup_opt(hover.info.first()), Some("Option")); + } + + #[test] + fn hover_enum_variant() { + check_hover_result( + r#" + //- /main.rs + enum Option { + /// The None variant + Non<|>e + } + "#, + &[" +None +``` + +The None variant + " + .trim()], + ); + + check_hover_result( + r#" + //- /main.rs + enum Option { + /// The Some variant + Some(T) + } + fn main() { + let s = Option::Som<|>e(12); + } + "#, + &[" +Some +``` + +The Some variant + " + .trim()], + ); } #[test] -- cgit v1.2.3 From b168104d95d112d254512090db3bc35ebf0fd5c2 Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Thu, 7 Mar 2019 20:58:41 +0200 Subject: Use ast::Name::text() instead of name().syntax().text() --- crates/ra_ide_api/src/hover.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 1c7d1f3fd..bf08f5203 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -227,7 +227,7 @@ impl NavigationTarget { let mut string = node.visibility().map(|v| format!("{} ", v.syntax().text())).unwrap_or_default(); string.push_str(label); - node.name()?.syntax().text().push_to(&mut string); + string.push_str(node.name()?.text().as_str()); Some(string) } @@ -241,7 +241,7 @@ impl NavigationTarget { .visit(|node: &ast::ConstDef| visit_ascribed_node(node, "const ")) .visit(|node: &ast::StaticDef| visit_ascribed_node(node, "static ")) .visit(|node: &ast::NamedFieldDef| visit_ascribed_node(node, "")) - .visit(|node: &ast::EnumVariant| Some(node.name()?.syntax().text().to_string())) + .visit(|node: &ast::EnumVariant| Some(node.name()?.text().to_string())) .accept(&node)? } } -- cgit v1.2.3