mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-06 20:28:33 +00:00
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 :
9a44f627be/crates/ra_ide/src/hover.rs (L173-L182)
Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
This commit is contained in:
commit
029c02982b
@ -128,7 +128,7 @@ fn hover_text_from_name_kind(db: &RootDatabase, name_kind: NameKind) -> Option<S
|
|||||||
hir::ModuleDef::TypeAlias(it) => from_def_source(db, it),
|
hir::ModuleDef::TypeAlias(it) => from_def_source(db, it),
|
||||||
hir::ModuleDef::BuiltinType(it) => Some(it.to_string()),
|
hir::ModuleDef::BuiltinType(it) => Some(it.to_string()),
|
||||||
},
|
},
|
||||||
Local(_) => None,
|
Local(it) => Some(rust_code_markup(it.ty(db).display_truncated(db, None).to_string())),
|
||||||
TypeParam(_) | SelfType(_) => {
|
TypeParam(_) | SelfType(_) => {
|
||||||
// FIXME: Hover for generic param
|
// FIXME: Hover for generic param
|
||||||
None
|
None
|
||||||
@ -174,6 +174,8 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
|
|||||||
.value
|
.value
|
||||||
.ancestors()
|
.ancestors()
|
||||||
.find(|n| ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some())?;
|
.find(|n| ast::Expr::cast(n.clone()).is_some() || ast::Pat::cast(n.clone()).is_some())?;
|
||||||
|
|
||||||
|
// The following logic will not work if token is coming from a macro
|
||||||
let frange = FileRange { file_id: position.file_id, range: node.text_range() };
|
let frange = FileRange { file_id: position.file_id, range: node.text_range() };
|
||||||
res.extend(type_of(db, frange).map(rust_code_markup));
|
res.extend(type_of(db, frange).map(rust_code_markup));
|
||||||
if res.is_empty() {
|
if res.is_empty() {
|
||||||
@ -729,4 +731,20 @@ fn func(foo: i32) { if true { <|>foo; }; }
|
|||||||
&["fn foo()"],
|
&["fn foo()"],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_hover_through_expr_in_macro() {
|
||||||
|
check_hover_result(
|
||||||
|
"
|
||||||
|
//- /lib.rs
|
||||||
|
macro_rules! id {
|
||||||
|
($($tt:tt)*) => { $($tt)* }
|
||||||
|
}
|
||||||
|
fn foo(bar:u32) {
|
||||||
|
let a = id!(ba<|>r);
|
||||||
|
}
|
||||||
|
",
|
||||||
|
&["u32"],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user