aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/hover.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/hover.rs')
-rw-r--r--crates/ra_ide_api/src/hover.rs48
1 files changed, 28 insertions, 20 deletions
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index ba328efa1..086e6dec3 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -117,27 +117,23 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
117 hir::AssocItem::Const(it) => from_def_source(db, it), 117 hir::AssocItem::Const(it) => from_def_source(db, it),
118 hir::AssocItem::TypeAlias(it) => from_def_source(db, it), 118 hir::AssocItem::TypeAlias(it) => from_def_source(db, it),
119 }), 119 }),
120 Some(Def(it)) => { 120 Some(Def(it)) => match it {
121 match it { 121 hir::ModuleDef::Module(it) => {
122 hir::ModuleDef::Module(it) => { 122 if let hir::ModuleSource::Module(it) = it.definition_source(db).ast {
123 if let hir::ModuleSource::Module(it) = it.definition_source(db).ast { 123 res.extend(hover_text(it.doc_comment_text(), it.short_label()))
124 res.extend(hover_text(it.doc_comment_text(), it.short_label()))
125 }
126 }
127 hir::ModuleDef::Function(it) => res.extend(from_def_source(db, it)),
128 hir::ModuleDef::Adt(Adt::Struct(it)) => res.extend(from_def_source(db, it)),
129 hir::ModuleDef::Adt(Adt::Union(it)) => res.extend(from_def_source(db, it)),
130 hir::ModuleDef::Adt(Adt::Enum(it)) => res.extend(from_def_source(db, it)),
131 hir::ModuleDef::EnumVariant(it) => res.extend(from_def_source(db, it)),
132 hir::ModuleDef::Const(it) => res.extend(from_def_source(db, it)),
133 hir::ModuleDef::Static(it) => res.extend(from_def_source(db, it)),
134 hir::ModuleDef::Trait(it) => res.extend(from_def_source(db, it)),
135 hir::ModuleDef::TypeAlias(it) => res.extend(from_def_source(db, it)),
136 hir::ModuleDef::BuiltinType(_) => {
137 // FIXME: hover for builtin Type ?
138 } 124 }
139 } 125 }
140 } 126 hir::ModuleDef::Function(it) => res.extend(from_def_source(db, it)),
127 hir::ModuleDef::Adt(Adt::Struct(it)) => res.extend(from_def_source(db, it)),
128 hir::ModuleDef::Adt(Adt::Union(it)) => res.extend(from_def_source(db, it)),
129 hir::ModuleDef::Adt(Adt::Enum(it)) => res.extend(from_def_source(db, it)),
130 hir::ModuleDef::EnumVariant(it) => res.extend(from_def_source(db, it)),
131 hir::ModuleDef::Const(it) => res.extend(from_def_source(db, it)),
132 hir::ModuleDef::Static(it) => res.extend(from_def_source(db, it)),
133 hir::ModuleDef::Trait(it) => res.extend(from_def_source(db, it)),
134 hir::ModuleDef::TypeAlias(it) => res.extend(from_def_source(db, it)),
135 hir::ModuleDef::BuiltinType(it) => res.extend(Some(it.to_string())),
136 },
141 Some(SelfType(ty)) => { 137 Some(SelfType(ty)) => {
142 if let Some((adt_def, _)) = ty.as_adt() { 138 if let Some((adt_def, _)) = ty.as_adt() {
143 res.extend(match adt_def { 139 res.extend(match adt_def {
@@ -147,7 +143,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
147 }) 143 })
148 } 144 }
149 } 145 }
150 Some(Pat(_)) | Some(SelfParam(_)) => { 146 Some(Local(_)) => {
151 // Hover for these shows type names 147 // Hover for these shows type names
152 no_fallback = true; 148 no_fallback = true;
153 } 149 }
@@ -722,4 +718,16 @@ fn func(foo: i32) { if true { <|>foo; }; }
722 assert_eq!(trim_markup_opt(hover.info.first()), Some("macro_rules! foo")); 718 assert_eq!(trim_markup_opt(hover.info.first()), Some("macro_rules! foo"));
723 assert_eq!(hover.info.is_exact(), true); 719 assert_eq!(hover.info.is_exact(), true);
724 } 720 }
721
722 #[test]
723 fn test_hover_tuple_field() {
724 let (analysis, position) = single_file_with_position(
725 "
726 struct TS(String, i32<|>);
727 ",
728 );
729 let hover = analysis.hover(position).unwrap().unwrap();
730 assert_eq!(trim_markup_opt(hover.info.first()), Some("i32"));
731 assert_eq!(hover.info.is_exact(), true);
732 }
725} 733}