From 5fc91058ff7a94ed90be1125c16670de5a6b268c Mon Sep 17 00:00:00 2001 From: Duong Do Minh Chau Date: Tue, 9 Mar 2021 15:36:41 +0700 Subject: Add completion to turn x.err into Err(x) --- crates/ide_completion/src/completions/postfix.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/crates/ide_completion/src/completions/postfix.rs b/crates/ide_completion/src/completions/postfix.rs index 9c34ed0b6..4884a42e2 100644 --- a/crates/ide_completion/src/completions/postfix.rs +++ b/crates/ide_completion/src/completions/postfix.rs @@ -180,8 +180,25 @@ pub(crate) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { ) .add_to(acc); - postfix_snippet(ctx, cap, &dot_receiver, "ok", "Ok(expr)", &format!("Ok({})", receiver_text)) - .add_to(acc); + postfix_snippet( + ctx, + cap, + &dot_receiver, + "ok", + "Ok(expr)", + &format!("Ok({})", receiver_text) + ) + .add_to(acc); + + postfix_snippet( + ctx, + cap, + &dot_receiver, + "err", + "Err(expr)", + &format!("Err({})", receiver_text) + ) + .add_to(acc); postfix_snippet( ctx, -- cgit v1.2.3 From ea835fc800b776e34bfebcd8457213360b4d6f13 Mon Sep 17 00:00:00 2001 From: Duong Do Minh Chau Date: Tue, 9 Mar 2021 15:48:53 +0700 Subject: Update the test to match the change --- crates/ide_completion/src/completions/postfix.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/ide_completion/src/completions/postfix.rs b/crates/ide_completion/src/completions/postfix.rs index 4884a42e2..3d153838d 100644 --- a/crates/ide_completion/src/completions/postfix.rs +++ b/crates/ide_completion/src/completions/postfix.rs @@ -342,6 +342,7 @@ fn main() { sn match match expr {} sn box Box::new(expr) sn ok Ok(expr) + sn err Err(expr) sn some Some(expr) sn dbg dbg!(expr) sn dbgr dbg!(&expr) @@ -374,6 +375,7 @@ fn main() { sn match match expr {} sn box Box::new(expr) sn ok Ok(expr) + sn err Err(expr) sn some Some(expr) sn dbg dbg!(expr) sn dbgr dbg!(&expr) @@ -397,6 +399,7 @@ fn main() { sn match match expr {} sn box Box::new(expr) sn ok Ok(expr) + sn err Err(expr) sn some Some(expr) sn dbg dbg!(expr) sn dbgr dbg!(&expr) @@ -425,6 +428,7 @@ fn main() { sn match match expr {} sn box Box::new(expr) sn ok Ok(expr) + sn err Err(expr) sn some Some(expr) sn dbg dbg!(expr) sn dbgr dbg!(&expr) -- cgit v1.2.3 From a068cedee019a02dd3f6d30169f3ed39e703f6c9 Mon Sep 17 00:00:00 2001 From: Duong Do Minh Chau Date: Tue, 9 Mar 2021 16:00:06 +0700 Subject: Add trailing commas --- crates/ide_completion/src/completions/postfix.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ide_completion/src/completions/postfix.rs b/crates/ide_completion/src/completions/postfix.rs index 3d153838d..0729b8eee 100644 --- a/crates/ide_completion/src/completions/postfix.rs +++ b/crates/ide_completion/src/completions/postfix.rs @@ -186,7 +186,7 @@ pub(crate) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { &dot_receiver, "ok", "Ok(expr)", - &format!("Ok({})", receiver_text) + &format!("Ok({})", receiver_text), ) .add_to(acc); @@ -196,7 +196,7 @@ pub(crate) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { &dot_receiver, "err", "Err(expr)", - &format!("Err({})", receiver_text) + &format!("Err({})", receiver_text), ) .add_to(acc); -- cgit v1.2.3 From 73590f0f0b0fa0b1c61c157682f4da7b0a7981ac Mon Sep 17 00:00:00 2001 From: Duong Do Minh Chau Date: Tue, 9 Mar 2021 16:38:07 +0700 Subject: Fix format --- crates/ide_completion/src/completions/postfix.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/crates/ide_completion/src/completions/postfix.rs b/crates/ide_completion/src/completions/postfix.rs index 0729b8eee..d45ad7944 100644 --- a/crates/ide_completion/src/completions/postfix.rs +++ b/crates/ide_completion/src/completions/postfix.rs @@ -180,15 +180,8 @@ pub(crate) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { ) .add_to(acc); - postfix_snippet( - ctx, - cap, - &dot_receiver, - "ok", - "Ok(expr)", - &format!("Ok({})", receiver_text), - ) - .add_to(acc); + postfix_snippet(ctx, cap, &dot_receiver, "ok", "Ok(expr)", &format!("Ok({})", receiver_text)) + .add_to(acc); postfix_snippet( ctx, -- cgit v1.2.3