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.rs49
1 files changed, 46 insertions, 3 deletions
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs
index aa48cb412..a632ea6a2 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).and_then(|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).and_then(|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),
@@ -1107,6 +1110,46 @@ fn bar() { fo<|>o(); }
1107 } 1110 }
1108 1111
1109 #[test] 1112 #[test]
1113 fn test_hover_extern_crate() {
1114 check(
1115 r#"
1116//- /main.rs
1117extern crate st<|>d;
1118//- /std/lib.rs
1119//! Standard library for this test
1120//!
1121//! Printed?
1122//! abc123
1123 "#,
1124 expect![[r#"
1125 *std*
1126 Standard library for this test
1127
1128 Printed?
1129 abc123
1130 "#]],
1131 );
1132 check(
1133 r#"
1134//- /main.rs
1135extern crate std as ab<|>c;
1136//- /std/lib.rs
1137//! Standard library for this test
1138//!
1139//! Printed?
1140//! abc123
1141 "#,
1142 expect![[r#"
1143 *abc*
1144 Standard library for this test
1145
1146 Printed?
1147 abc123
1148 "#]],
1149 );
1150 }
1151
1152 #[test]
1110 fn test_hover_mod_with_same_name_as_function() { 1153 fn test_hover_mod_with_same_name_as_function() {
1111 check( 1154 check(
1112 r#" 1155 r#"