mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-01 07:48:45 +00:00
Auto merge of #14160 - Veykril:hover-call, r=Veykril
fix: Bring back hovering call parens for return type info
This commit is contained in:
commit
1f2d33fb40
3 changed files with 53 additions and 1 deletions
|
@ -201,6 +201,23 @@ fn hover_simple(
|
||||||
|
|
||||||
Some(render::struct_rest_pat(sema, config, &record_pat))
|
Some(render::struct_rest_pat(sema, config, &record_pat))
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
// try () call hovers
|
||||||
|
.or_else(|| {
|
||||||
|
descended().find_map(|token| {
|
||||||
|
if token.kind() != T!['('] && token.kind() != T![')'] {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let arg_list = token.parent().and_then(ast::ArgList::cast)?.syntax().parent()?;
|
||||||
|
let call_expr = syntax::match_ast! {
|
||||||
|
match arg_list {
|
||||||
|
ast::CallExpr(expr) => expr.into(),
|
||||||
|
ast::MethodCallExpr(expr) => expr.into(),
|
||||||
|
_ => return None,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
render::type_info_of(sema, config, &Either::Left(call_expr))
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
result.map(|mut res: HoverResult| {
|
result.map(|mut res: HoverResult| {
|
||||||
|
|
|
@ -5612,3 +5612,38 @@ fn main() {
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn hover_call_parens() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
fn foo() -> i32 {}
|
||||||
|
fn main() {
|
||||||
|
foo($0);
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
*)*
|
||||||
|
```rust
|
||||||
|
i32
|
||||||
|
```
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
struct S;
|
||||||
|
impl S {
|
||||||
|
fn foo(self) -> i32 {}
|
||||||
|
}
|
||||||
|
fn main() {
|
||||||
|
S.foo($0);
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
*)*
|
||||||
|
```rust
|
||||||
|
i32
|
||||||
|
```
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
@ -186,7 +186,7 @@ impl SourceFile {
|
||||||
/// ```
|
/// ```
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! match_ast {
|
macro_rules! match_ast {
|
||||||
(match $node:ident { $($tt:tt)* }) => { match_ast!(match ($node) { $($tt)* }) };
|
(match $node:ident { $($tt:tt)* }) => { $crate::match_ast!(match ($node) { $($tt)* }) };
|
||||||
|
|
||||||
(match ($node:expr) {
|
(match ($node:expr) {
|
||||||
$( $( $path:ident )::+ ($it:pat) => $res:expr, )*
|
$( $( $path:ident )::+ ($it:pat) => $res:expr, )*
|
||||||
|
|
Loading…
Reference in a new issue