Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #21557 from A4-Tacks/let-postfix-in-cond
feat: fallback let postfix completions in condition
Chayim Refael Friedman 3 months ago
parent e1baa44 · parent f13c3d2 · commit 631e3ab
-rw-r--r--crates/ide-completion/src/completions/postfix.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/crates/ide-completion/src/completions/postfix.rs b/crates/ide-completion/src/completions/postfix.rs
index 7f67ef848e..4b244c9025 100644
--- a/crates/ide-completion/src/completions/postfix.rs
+++ b/crates/ide-completion/src/completions/postfix.rs
@@ -151,6 +151,10 @@ pub(crate) fn complete_postfix(
.add_to(acc, ctx.db);
}
},
+ _ if is_in_cond => {
+ postfix_snippet("let", "let", &format!("let $1 = {receiver_text}"))
+ .add_to(acc, ctx.db);
+ }
_ if matches!(second_ancestor.kind(), STMT_LIST | EXPR_STMT) => {
postfix_snippet("let", "let", &format!("let $0 = {receiver_text};"))
.add_to(acc, ctx.db);
@@ -745,6 +749,25 @@ fn main() {
}
#[test]
+ fn iflet_fallback_cond() {
+ check_edit(
+ "let",
+ r#"
+fn main() {
+ let bar = 2;
+ if bar.$0
+}
+"#,
+ r#"
+fn main() {
+ let bar = 2;
+ if let $1 = bar
+}
+"#,
+ );
+ }
+
+ #[test]
fn option_letelse() {
check_edit(
"lete",