aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/hover.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/hover.rs')
-rw-r--r--crates/ra_ide/src/hover.rs88
1 files changed, 81 insertions, 7 deletions
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs
index aa48cb412..f66f62bfb 100644
--- a/crates/ra_ide/src/hover.rs
+++ b/crates/ra_ide/src/hover.rs
@@ -85,8 +85,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
85 let node = token.parent(); 85 let node = token.parent();
86 let definition = match_ast! { 86 let definition = match_ast! {
87 match node { 87 match node {
88 ast::NameRef(name_ref) => classify_name_ref(&sema, &name_ref).map(|d| d.definition()), 88 ast::NameRef(name_ref) => classify_name_ref(&sema, &name_ref).map(|d| d.definition(sema.db)),
89 ast::Name(name) => classify_name(&sema, &name).map(|d| d.definition()), 89 ast::Name(name) => classify_name(&sema, &name).map(|d| d.definition(sema.db)),
90 _ => None, 90 _ => None,
91 } 91 }
92 }; 92 };
@@ -304,7 +304,10 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
304 let docs = Documentation::from_ast(&it).map(Into::into); 304 let docs = Documentation::from_ast(&it).map(Into::into);
305 hover_markup(docs, it.short_label(), mod_path) 305 hover_markup(docs, it.short_label(), mod_path)
306 } 306 }
307 _ => None, 307 ModuleSource::SourceFile(it) => {
308 let docs = Documentation::from_ast(&it).map(Into::into);
309 hover_markup(docs, it.short_label(), mod_path)
310 }
308 }, 311 },
309 ModuleDef::Function(it) => from_def_source(db, it, mod_path), 312 ModuleDef::Function(it) => from_def_source(db, it, mod_path),
310 ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path), 313 ModuleDef::Adt(Adt::Struct(it)) => from_def_source(db, it, mod_path),
@@ -509,6 +512,37 @@ fn main() { }
509 } 512 }
510 513
511 #[test] 514 #[test]
515 fn hover_shows_fn_doc() {
516 check(
517 r#"
518/// # Example
519/// ```
520/// # use std::path::Path;
521/// #
522/// foo(Path::new("hello, world!"))
523/// ```
524pub fn foo<|>(_: &Path) {}
525
526fn main() { }
527"#,
528 expect![[r#"
529 *foo*
530 ```rust
531 pub fn foo(_: &Path)
532 ```
533 ___
534
535 # Example
536 ```
537 # use std::path::Path;
538 #
539 foo(Path::new("hello, world!"))
540 ```
541 "#]],
542 );
543 }
544
545 #[test]
512 fn hover_shows_struct_field_info() { 546 fn hover_shows_struct_field_info() {
513 // Hovering over the field when instantiating 547 // Hovering over the field when instantiating
514 check( 548 check(
@@ -556,16 +590,16 @@ fn main() {
556 #[test] 590 #[test]
557 fn hover_const_static() { 591 fn hover_const_static() {
558 check( 592 check(
559 r#"const foo<|>: u32 = 0;"#, 593 r#"const foo<|>: u32 = 123;"#,
560 expect![[r#" 594 expect![[r#"
561 *foo* 595 *foo*
562 ```rust 596 ```rust
563 const foo: u32 597 const foo: u32 = 123
564 ``` 598 ```
565 "#]], 599 "#]],
566 ); 600 );
567 check( 601 check(
568 r#"static foo<|>: u32 = 0;"#, 602 r#"static foo<|>: u32 = 456;"#,
569 expect![[r#" 603 expect![[r#"
570 *foo* 604 *foo*
571 ```rust 605 ```rust
@@ -800,7 +834,7 @@ fn main() {
800 expect![[r#" 834 expect![[r#"
801 *C* 835 *C*
802 ```rust 836 ```rust
803 const C: u32 837 const C: u32 = 1
804 ``` 838 ```
805 "#]], 839 "#]],
806 ) 840 )
@@ -1107,6 +1141,46 @@ fn bar() { fo<|>o(); }
1107 } 1141 }
1108 1142
1109 #[test] 1143 #[test]
1144 fn test_hover_extern_crate() {
1145 check(
1146 r#"
1147//- /main.rs
1148extern crate st<|>d;
1149//- /std/lib.rs
1150//! Standard library for this test
1151//!
1152//! Printed?
1153//! abc123
1154 "#,
1155 expect![[r#"
1156 *std*
1157 Standard library for this test
1158
1159 Printed?
1160 abc123
1161 "#]],
1162 );
1163 check(
1164 r#"
1165//- /main.rs
1166extern crate std as ab<|>c;
1167//- /std/lib.rs
1168//! Standard library for this test
1169//!
1170//! Printed?
1171//! abc123
1172 "#,
1173 expect![[r#"
1174 *abc*
1175 Standard library for this test
1176
1177 Printed?
1178 abc123
1179 "#]],
1180 );
1181 }
1182
1183 #[test]
1110 fn test_hover_mod_with_same_name_as_function() { 1184 fn test_hover_mod_with_same_name_as_function() {
1111 check( 1185 check(
1112 r#" 1186 r#"