aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_ide/src/hover.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs
index 35e39f965..5548681f1 100644
--- a/crates/ra_ide/src/hover.rs
+++ b/crates/ra_ide/src/hover.rs
@@ -128,7 +128,7 @@ fn hover_text_from_name_kind(db: &RootDatabase, name_kind: NameKind) -> Option<S
128 hir::ModuleDef::TypeAlias(it) => from_def_source(db, it), 128 hir::ModuleDef::TypeAlias(it) => from_def_source(db, it),
129 hir::ModuleDef::BuiltinType(it) => Some(it.to_string()), 129 hir::ModuleDef::BuiltinType(it) => Some(it.to_string()),
130 }, 130 },
131 Local(_) => None, 131 Local(it) => Some(rust_code_markup(it.ty(db).display_truncated(db, None).to_string())),
132 TypeParam(_) | SelfType(_) => { 132 TypeParam(_) | SelfType(_) => {
133 // FIXME: Hover for generic param 133 // FIXME: Hover for generic param
134 None 134 None
@@ -174,6 +174,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
174 .value 174 .value
175 .ancestors() 175 .ancestors()
176 .find(|n| ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some())?; 176 .find(|n| ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some())?;
177
178 // The following logic will not work if token is coming from a macro
177 let frange = FileRange { file_id: position.file_id, range: node.text_range() }; 179 let frange = FileRange { file_id: position.file_id, range: node.text_range() };
178 res.extend(type_of(db, frange).map(rust_code_markup)); 180 res.extend(type_of(db, frange).map(rust_code_markup));
179 if res.is_empty() { 181 if res.is_empty() {
@@ -729,4 +731,20 @@ fn func(foo: i32) { if true { <|>foo; }; }
729 &["fn foo()"], 731 &["fn foo()"],
730 ); 732 );
731 } 733 }
734
735 #[test]
736 fn test_hover_through_expr_in_macro() {
737 check_hover_result(
738 "
739 //- /lib.rs
740 macro_rules! id {
741 ($($tt:tt)*) => { $($tt)* }
742 }
743 fn foo(bar:u32) {
744 let a = id!(ba<|>r);
745 }
746 ",
747 &["u32"],
748 );
749 }
732} 750}