aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-01-10 17:58:14 +0000
committerGitHub <[email protected]>2020-01-10 17:58:14 +0000
commit029c02982b4ab89dc785bc162456dbe25a22446c (patch)
tree04029c58d338fb15a47dae93313c840fa8896ef3 /crates/ra_ide/src
parent9a44f627be0b3c49184e3ad594849f9b5ed78daa (diff)
parent19094abd41fe398c2ba1a3c4926ef50c04eebabb (diff)
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 <[email protected]>
Diffstat (limited to 'crates/ra_ide/src')
-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}