Skip to content

Commit 19094ab

Browse files
committed
Proper handling local in hover
1 parent 2068e48 commit 19094ab

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

crates/ra_ide/src/hover.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn hover_text_from_name_kind(db: &RootDatabase, name_kind: NameKind) -> Option<S
128128
hir::ModuleDef::TypeAlias(it) => from_def_source(db, it),
129129
hir::ModuleDef::BuiltinType(it) => Some(it.to_string()),
130130
},
131-
Local(_) => None,
131+
Local(it) => Some(rust_code_markup(it.ty(db).display_truncated(db, None).to_string())),
132132
TypeParam(_) | SelfType(_) => {
133133
// FIXME: Hover for generic param
134134
None
@@ -174,6 +174,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
174174
.value
175175
.ancestors()
176176
.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
177179
let frange = FileRange { file_id: position.file_id, range: node.text_range() };
178180
res.extend(type_of(db, frange).map(rust_code_markup));
179181
if res.is_empty() {
@@ -729,4 +731,20 @@ fn func(foo: i32) { if true { <|>foo; }; }
729731
&["fn foo()"],
730732
);
731733
}
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+
}
732750
}

0 commit comments

Comments
 (0)