about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-02-15 17:59:31 +0000
committerbors <bors@rust-lang.org>2023-02-15 17:59:31 +0000
commit1f2d33fb40548178d4ced3f0f971540c910d7ed9 (patch)
tree05685e6ecdda276720906a48f90b8784ab755b9a
parentdd582dac67e35365dff25c8a299c6e7e0f08dd3e (diff)
parente550e553e01d026555be58a41828542306e7e019 (diff)
downloadrust-1f2d33fb40548178d4ced3f0f971540c910d7ed9.tar.gz
rust-1f2d33fb40548178d4ced3f0f971540c910d7ed9.zip
Auto merge of #14160 - Veykril:hover-call, r=Veykril
fix: Bring back hovering call parens for return type info
-rw-r--r--crates/ide/src/hover.rs17
-rw-r--r--crates/ide/src/hover/tests.rs35
-rw-r--r--crates/syntax/src/lib.rs2
3 files changed, 53 insertions, 1 deletions
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs
index 2058a4f5f19..5f2c61f5b5f 100644
--- a/crates/ide/src/hover.rs
+++ b/crates/ide/src/hover.rs
@@ -201,6 +201,23 @@ fn hover_simple(
 
                 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| {
diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs
index 2830212add8..bd7ce2f1d0d 100644
--- a/crates/ide/src/hover/tests.rs
+++ b/crates/ide/src/hover/tests.rs
@@ -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
+            ```
+        "#]],
+    );
+}
diff --git a/crates/syntax/src/lib.rs b/crates/syntax/src/lib.rs
index 84c66b27e69..6f57cbad66b 100644
--- a/crates/syntax/src/lib.rs
+++ b/crates/syntax/src/lib.rs
@@ -186,7 +186,7 @@ impl SourceFile {
 /// ```
 #[macro_export]
 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) {
         $( $( $path:ident )::+ ($it:pat) => $res:expr, )*