From 3188c1451a6f1237859dcb813debef9fa537195c Mon Sep 17 00:00:00 2001 From: Jeremy Kolb Date: Sun, 10 Nov 2019 13:59:39 -0500 Subject: Hover for builtins --- crates/ra_ide_api/src/hover.rs | 50 ++++++++++++++++++++++++++---------------- 1 file 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 @@ //! FIXME: write short doc here -use hir::{Adt, HasSource, HirDisplay}; +use hir::{Adt, BuiltinType, HasSource, HirDisplay}; use ra_db::SourceDatabase; use ra_syntax::{ algo::{ancestors_at_offset, find_covering_element, find_node_at_offset}, @@ -117,27 +117,27 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option from_def_source(db, it), hir::AssocItem::TypeAlias(it) => from_def_source(db, it), }), - Some(Def(it)) => { - match it { - hir::ModuleDef::Module(it) => { - if let hir::ModuleSource::Module(it) = it.definition_source(db).ast { - res.extend(hover_text(it.doc_comment_text(), it.short_label())) - } + Some(Def(it)) => match it { + hir::ModuleDef::Module(it) => { + if let hir::ModuleSource::Module(it) = it.definition_source(db).ast { + res.extend(hover_text(it.doc_comment_text(), it.short_label())) } - hir::ModuleDef::Function(it) => res.extend(from_def_source(db, it)), - hir::ModuleDef::Adt(Adt::Struct(it)) => res.extend(from_def_source(db, it)), - hir::ModuleDef::Adt(Adt::Union(it)) => res.extend(from_def_source(db, it)), - hir::ModuleDef::Adt(Adt::Enum(it)) => res.extend(from_def_source(db, it)), - hir::ModuleDef::EnumVariant(it) => res.extend(from_def_source(db, it)), - hir::ModuleDef::Const(it) => res.extend(from_def_source(db, it)), - hir::ModuleDef::Static(it) => res.extend(from_def_source(db, it)), - hir::ModuleDef::Trait(it) => res.extend(from_def_source(db, it)), - hir::ModuleDef::TypeAlias(it) => res.extend(from_def_source(db, it)), - hir::ModuleDef::BuiltinType(_) => { - // FIXME: hover for builtin Type ? + } + hir::ModuleDef::Function(it) => res.extend(from_def_source(db, it)), + hir::ModuleDef::Adt(Adt::Struct(it)) => res.extend(from_def_source(db, it)), + hir::ModuleDef::Adt(Adt::Union(it)) => res.extend(from_def_source(db, it)), + hir::ModuleDef::Adt(Adt::Enum(it)) => res.extend(from_def_source(db, it)), + hir::ModuleDef::EnumVariant(it) => res.extend(from_def_source(db, it)), + hir::ModuleDef::Const(it) => res.extend(from_def_source(db, it)), + hir::ModuleDef::Static(it) => res.extend(from_def_source(db, it)), + hir::ModuleDef::Trait(it) => res.extend(from_def_source(db, it)), + hir::ModuleDef::TypeAlias(it) => res.extend(from_def_source(db, it)), + hir::ModuleDef::BuiltinType(it) => { + if let Some(b) = BuiltinType::ALL.iter().find(|(_, ty)| *ty == it) { + res.extend(Some(b.0.to_string())) } } - } + }, Some(SelfType(ty)) => { if let Some((adt_def, _)) = ty.as_adt() { res.extend(match adt_def { @@ -722,4 +722,16 @@ fn func(foo: i32) { if true { <|>foo; }; } assert_eq!(trim_markup_opt(hover.info.first()), Some("macro_rules! foo")); assert_eq!(hover.info.is_exact(), true); } + + #[test] + fn test_hover_tuple_field() { + let (analysis, position) = single_file_with_position( + " + struct TS(String, i32<|>); + ", + ); + let hover = analysis.hover(position).unwrap().unwrap(); + assert_eq!(trim_markup_opt(hover.info.first()), Some("i32")); + assert_eq!(hover.info.is_exact(), true); + } } -- cgit v1.2.3