diff options
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r-- | crates/ra_ide_api/src/hover.rs | 58 |
1 files changed, 56 insertions, 2 deletions
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 { | |||
195 | .visit(doc_comments::<ast::ConstDef>) | 195 | .visit(doc_comments::<ast::ConstDef>) |
196 | .visit(doc_comments::<ast::StaticDef>) | 196 | .visit(doc_comments::<ast::StaticDef>) |
197 | .visit(doc_comments::<ast::NamedFieldDef>) | 197 | .visit(doc_comments::<ast::NamedFieldDef>) |
198 | .visit(doc_comments::<ast::EnumVariant>) | ||
198 | .accept(&node)? | 199 | .accept(&node)? |
199 | } | 200 | } |
200 | 201 | ||
@@ -240,6 +241,7 @@ impl NavigationTarget { | |||
240 | .visit(|node: &ast::ConstDef| visit_ascribed_node(node, "const ")) | 241 | .visit(|node: &ast::ConstDef| visit_ascribed_node(node, "const ")) |
241 | .visit(|node: &ast::StaticDef| visit_ascribed_node(node, "static ")) | 242 | .visit(|node: &ast::StaticDef| visit_ascribed_node(node, "static ")) |
242 | .visit(|node: &ast::NamedFieldDef| visit_ascribed_node(node, "")) | 243 | .visit(|node: &ast::NamedFieldDef| visit_ascribed_node(node, "")) |
244 | .visit(|node: &ast::EnumVariant| Some(node.name()?.syntax().text().to_string())) | ||
243 | .accept(&node)? | 245 | .accept(&node)? |
244 | } | 246 | } |
245 | } | 247 | } |
@@ -428,8 +430,60 @@ mod tests { | |||
428 | ", | 430 | ", |
429 | ); | 431 | ); |
430 | let hover = analysis.hover(position).unwrap().unwrap(); | 432 | let hover = analysis.hover(position).unwrap().unwrap(); |
431 | // not the nicest way to show it currently | 433 | assert_eq!(trim_markup_opt(hover.info.first()), Some("Some")); |
432 | assert_eq!(trim_markup_opt(hover.info.first()), Some("Some<i32>(T) -> Option<T>")); | 434 | |
435 | let (analysis, position) = single_file_with_position( | ||
436 | " | ||
437 | enum Option<T> { Some(T) } | ||
438 | use Option::Some; | ||
439 | |||
440 | fn main() { | ||
441 | let b<|>ar = Some(12); | ||
442 | } | ||
443 | ", | ||
444 | ); | ||
445 | let hover = analysis.hover(position).unwrap().unwrap(); | ||
446 | assert_eq!(trim_markup_opt(hover.info.first()), Some("Option<i32>")); | ||
447 | } | ||
448 | |||
449 | #[test] | ||
450 | fn hover_enum_variant() { | ||
451 | check_hover_result( | ||
452 | r#" | ||
453 | //- /main.rs | ||
454 | enum Option<T> { | ||
455 | /// The None variant | ||
456 | Non<|>e | ||
457 | } | ||
458 | "#, | ||
459 | &[" | ||
460 | None | ||
461 | ``` | ||
462 | |||
463 | The None variant | ||
464 | " | ||
465 | .trim()], | ||
466 | ); | ||
467 | |||
468 | check_hover_result( | ||
469 | r#" | ||
470 | //- /main.rs | ||
471 | enum Option<T> { | ||
472 | /// The Some variant | ||
473 | Some(T) | ||
474 | } | ||
475 | fn main() { | ||
476 | let s = Option::Som<|>e(12); | ||
477 | } | ||
478 | "#, | ||
479 | &[" | ||
480 | Some | ||
481 | ``` | ||
482 | |||
483 | The Some variant | ||
484 | " | ||
485 | .trim()], | ||
486 | ); | ||
433 | } | 487 | } |
434 | 488 | ||
435 | #[test] | 489 | #[test] |