about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorChayim Refael Friedman <chayimfr@gmail.com>2024-09-22 06:07:49 +0300
committerChayim Refael Friedman <chayimfr@gmail.com>2024-09-22 06:07:49 +0300
commitded3a5cd89da1fa2fc0a26adbd509f9c8ff5246b (patch)
tree641d9f72b10d2ac7a5df4edd94b2cdb83f109806 /src
parent2818d1e8508f569285bca47161ab7c293e051e9f (diff)
downloadrust-ded3a5cd89da1fa2fc0a26adbd509f9c8ff5246b.tar.gz
rust-ded3a5cd89da1fa2fc0a26adbd509f9c8ff5246b.zip
Include dereferences in consuming postfix completions (e.g. `call`)
Diffstat (limited to 'src')
-rw-r--r--src/tools/rust-analyzer/crates/ide-completion/src/completions/postfix.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/tools/rust-analyzer/crates/ide-completion/src/completions/postfix.rs b/src/tools/rust-analyzer/crates/ide-completion/src/completions/postfix.rs
index 2ede799c875..d3579fd8cc6 100644
--- a/src/tools/rust-analyzer/crates/ide-completion/src/completions/postfix.rs
+++ b/src/tools/rust-analyzer/crates/ide-completion/src/completions/postfix.rs
@@ -294,6 +294,18 @@ fn include_references(initial_element: &ast::Expr) -> (ast::Expr, ast::Expr) {
 
     let mut new_element_opt = initial_element.clone();
 
+    while let Some(parent_deref_element) =
+        resulting_element.syntax().parent().and_then(ast::PrefixExpr::cast)
+    {
+        if parent_deref_element.op_kind() != Some(ast::UnaryOp::Deref) {
+            break;
+        }
+
+        resulting_element = ast::Expr::from(parent_deref_element);
+
+        new_element_opt = make::expr_prefix(syntax::T![*], new_element_opt);
+    }
+
     if let Some(first_ref_expr) = resulting_element.syntax().parent().and_then(ast::RefExpr::cast) {
         if let Some(expr) = first_ref_expr.expr() {
             resulting_element = expr;
@@ -875,4 +887,23 @@ fn main() {
 "#,
         );
     }
+
+    #[test]
+    fn deref_consuming() {
+        check_edit(
+            "call",
+            r#"
+fn main() {
+    let mut x = &mut 2;
+    &mut *x.$0;
+}
+"#,
+            r#"
+fn main() {
+    let mut x = &mut 2;
+    ${1}(&mut *x);
+}
+"#,
+        );
+    }
 }