]> git.lizzy.rs Git - rust.git/blobdiff - src/tools/rust-analyzer/crates/ide-completion/src/completions/postfix.rs
Rollup merge of #101967 - jmillikin:linux-abstract-socket-addr, r=joshtriplett
[rust.git] / src / tools / rust-analyzer / crates / ide-completion / src / completions / postfix.rs
index 9a891cea2d458491979475f1753b1f3f67b69645..b9bd47f7da504609b4c3b78947bd00bc9774164a 100644 (file)
@@ -69,10 +69,6 @@ pub(crate) fn complete_postfix(
         }
     }
 
-    if !ctx.config.snippets.is_empty() {
-        add_custom_postfix_completions(acc, ctx, &postfix_snippet, &receiver_text);
-    }
-
     let try_enum = TryEnum::from_ty(&ctx.sema, &receiver_ty.strip_references());
     if let Some(try_enum) = &try_enum {
         match try_enum {
@@ -140,6 +136,10 @@ pub(crate) fn complete_postfix(
         None => return,
     };
 
+    if !ctx.config.snippets.is_empty() {
+        add_custom_postfix_completions(acc, ctx, &postfix_snippet, &receiver_text);
+    }
+
     match try_enum {
         Some(try_enum) => match try_enum {
             TryEnum::Result => {
@@ -613,4 +613,25 @@ fn postfix_completion_for_format_like_strings() {
             r#"fn main() { log::error!("{}", 2+2) }"#,
         );
     }
+
+    #[test]
+    fn postfix_custom_snippets_completion_for_references() {
+        check_edit_with_config(
+            CompletionConfig {
+                snippets: vec![Snippet::new(
+                    &[],
+                    &["ok".into()],
+                    &["Ok(${receiver})".into()],
+                    "",
+                    &[],
+                    crate::SnippetScope::Expr,
+                )
+                .unwrap()],
+                ..TEST_CONFIG
+            },
+            "ok",
+            r#"fn main() { &&42.$0 }"#,
+            r#"fn main() { Ok(&&42) }"#,
+        );
+    }
 }