Skip to content

Commit 1f2d33f

Browse files
committed
Auto merge of #14160 - Veykril:hover-call, r=Veykril
fix: Bring back hovering call parens for return type info
2 parents dd582da + e550e55 commit 1f2d33f

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

crates/ide/src/hover.rs

+17
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,23 @@ fn hover_simple(
201201

202202
Some(render::struct_rest_pat(sema, config, &record_pat))
203203
})
204+
})
205+
// try () call hovers
206+
.or_else(|| {
207+
descended().find_map(|token| {
208+
if token.kind() != T!['('] && token.kind() != T![')'] {
209+
return None;
210+
}
211+
let arg_list = token.parent().and_then(ast::ArgList::cast)?.syntax().parent()?;
212+
let call_expr = syntax::match_ast! {
213+
match arg_list {
214+
ast::CallExpr(expr) => expr.into(),
215+
ast::MethodCallExpr(expr) => expr.into(),
216+
_ => return None,
217+
}
218+
};
219+
render::type_info_of(sema, config, &Either::Left(call_expr))
220+
})
204221
});
205222

206223
result.map(|mut res: HoverResult| {

crates/ide/src/hover/tests.rs

+35
Original file line numberDiff line numberDiff line change
@@ -5612,3 +5612,38 @@ fn main() {
56125612
"#,
56135613
);
56145614
}
5615+
5616+
#[test]
5617+
fn hover_call_parens() {
5618+
check(
5619+
r#"
5620+
fn foo() -> i32 {}
5621+
fn main() {
5622+
foo($0);
5623+
}
5624+
"#,
5625+
expect![[r#"
5626+
*)*
5627+
```rust
5628+
i32
5629+
```
5630+
"#]],
5631+
);
5632+
check(
5633+
r#"
5634+
struct S;
5635+
impl S {
5636+
fn foo(self) -> i32 {}
5637+
}
5638+
fn main() {
5639+
S.foo($0);
5640+
}
5641+
"#,
5642+
expect![[r#"
5643+
*)*
5644+
```rust
5645+
i32
5646+
```
5647+
"#]],
5648+
);
5649+
}

crates/syntax/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl SourceFile {
186186
/// ```
187187
#[macro_export]
188188
macro_rules! match_ast {
189-
(match $node:ident { $($tt:tt)* }) => { match_ast!(match ($node) { $($tt)* }) };
189+
(match $node:ident { $($tt:tt)* }) => { $crate::match_ast!(match ($node) { $($tt)* }) };
190190

191191
(match ($node:expr) {
192192
$( $( $path:ident )::+ ($it:pat) => $res:expr, )*

0 commit comments

Comments
 (0)