aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src
diff options
context:
space:
mode:
authorJeremy Kolb <[email protected]>2019-11-10 18:59:39 +0000
committerJeremy Kolb <[email protected]>2019-11-10 18:59:39 +0000
commit3188c1451a6f1237859dcb813debef9fa537195c (patch)
tree205cf0c3d2ab47a32b139b61ec34ca33e2afb782 /crates/ra_ide_api/src
parent9d786ea221b27fbdf7c7f7beea0290db448e0611 (diff)
Hover for builtins
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r--crates/ra_ide_api/src/hover.rs50
1 files changed, 31 insertions, 19 deletions
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs
index ba328efa1..244c65814 100644
--- a/crates/ra_ide_api/src/hover.rs
+++ b/crates/ra_ide_api/src/hover.rs
@@ -1,6 +1,6 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use hir::{Adt, HasSource, HirDisplay}; 3use hir::{Adt, BuiltinType, HasSource, HirDisplay};
4use ra_db::SourceDatabase; 4use ra_db::SourceDatabase;
5use ra_syntax::{ 5use ra_syntax::{
6 algo::{ancestors_at_offset, find_covering_element, find_node_at_offset}, 6 algo::{ancestors_at_offset, find_covering_element, find_node_at_offset},
@@ -117,27 +117,27 @@ 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 } 124 }
127 hir::ModuleDef::Function(it) => res.extend(from_def_source(db, it)), 125 }
128 hir::ModuleDef::Adt(Adt::Struct(it)) => res.extend(from_def_source(db, it)), 126 hir::ModuleDef::Function(it) => res.extend(from_def_source(db, it)),
129 hir::ModuleDef::Adt(Adt::Union(it)) => res.extend(from_def_source(db, it)), 127 hir::ModuleDef::Adt(Adt::Struct(it)) => res.extend(from_def_source(db, it)),
130 hir::ModuleDef::Adt(Adt::Enum(it)) => res.extend(from_def_source(db, it)), 128 hir::ModuleDef::Adt(Adt::Union(it)) => res.extend(from_def_source(db, it)),
131 hir::ModuleDef::EnumVariant(it) => res.extend(from_def_source(db, it)), 129 hir::ModuleDef::Adt(Adt::Enum(it)) => res.extend(from_def_source(db, it)),
132 hir::ModuleDef::Const(it) => res.extend(from_def_source(db, it)), 130 hir::ModuleDef::EnumVariant(it) => res.extend(from_def_source(db, it)),
133 hir::ModuleDef::Static(it) => res.extend(from_def_source(db, it)), 131 hir::ModuleDef::Const(it) => res.extend(from_def_source(db, it)),
134 hir::ModuleDef::Trait(it) => res.extend(from_def_source(db, it)), 132 hir::ModuleDef::Static(it) => res.extend(from_def_source(db, it)),
135 hir::ModuleDef::TypeAlias(it) => res.extend(from_def_source(db, it)), 133 hir::ModuleDef::Trait(it) => res.extend(from_def_source(db, it)),
136 hir::ModuleDef::BuiltinType(_) => { 134 hir::ModuleDef::TypeAlias(it) => res.extend(from_def_source(db, it)),
137 // FIXME: hover for builtin Type ? 135 hir::ModuleDef::BuiltinType(it) => {
136 if let Some(b) = BuiltinType::ALL.iter().find(|(_, ty)| *ty == it) {
137 res.extend(Some(b.0.to_string()))
138 } 138 }
139 } 139 }
140 } 140 },
141 Some(SelfType(ty)) => { 141 Some(SelfType(ty)) => {
142 if let Some((adt_def, _)) = ty.as_adt() { 142 if let Some((adt_def, _)) = ty.as_adt() {
143 res.extend(match adt_def { 143 res.extend(match adt_def {
@@ -722,4 +722,16 @@ fn func(foo: i32) { if true { <|>foo; }; }
722 assert_eq!(trim_markup_opt(hover.info.first()), Some("macro_rules! foo")); 722 assert_eq!(trim_markup_opt(hover.info.first()), Some("macro_rules! foo"));
723 assert_eq!(hover.info.is_exact(), true); 723 assert_eq!(hover.info.is_exact(), true);
724 } 724 }
725
726 #[test]
727 fn test_hover_tuple_field() {
728 let (analysis, position) = single_file_with_position(
729 "
730 struct TS(String, i32<|>);
731 ",
732 );
733 let hover = analysis.hover(position).unwrap().unwrap();
734 assert_eq!(trim_markup_opt(hover.info.first()), Some("i32"));
735 assert_eq!(hover.info.is_exact(), true);
736 }
725} 737}