Skip to content

Commit 029c029

Browse files
Merge #2786
2786: Proper handling local in hover r=flodiebold a=edwin0cheng This PR implement back the `Local` hover information generation, which is fall back to a general case catch previously : https://github.com/rust-analyzer/rust-analyzer/blob/9a44f627be0b3c49184e3ad594849f9b5ed78daa/crates/ra_ide/src/hover.rs#L173-L182 Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2 parents 9a44f62 + 19094ab commit 029c029

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)