aboutsummaryrefslogtreecommitdiff
path: root/crates/completion/src/completions/pattern.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-02-09 19:38:39 +0000
committerGitHub <[email protected]>2021-02-09 19:38:39 +0000
commit5d4ae1c8e3b76798fcb5eb656d886fe65a2c7277 (patch)
treed0387217488358ca8c9ba0776b641e41133c1761 /crates/completion/src/completions/pattern.rs
parent4f9a5287bfea124b76571424ce3eb4a91aec337a (diff)
parente92180a1d8c964d386fc5ffb80bfb05abdb6c153 (diff)
Merge #7616
7616: Show `Self` pattern and Self-prefixed enum-variant completions r=Veykril a=Veykril ![jDfQXNE0qZ](https://user-images.githubusercontent.com/3757771/107413514-1ff99b00-6b11-11eb-88b3-126cd106b514.gif) ![JpogVIgloq](https://user-images.githubusercontent.com/3757771/107413519-212ac800-6b11-11eb-8282-51115468dccc.gif) Variant pattern completions are to be done still. Closes #6549, at least that should address all that's left from that issue from what I can see. Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/completion/src/completions/pattern.rs')
-rw-r--r--crates/completion/src/completions/pattern.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/crates/completion/src/completions/pattern.rs b/crates/completion/src/completions/pattern.rs
index 595160ff5..43a5160cb 100644
--- a/crates/completion/src/completions/pattern.rs
+++ b/crates/completion/src/completions/pattern.rs
@@ -31,6 +31,14 @@ pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) {
31 _ => false, 31 _ => false,
32 }, 32 },
33 hir::ScopeDef::MacroDef(_) => true, 33 hir::ScopeDef::MacroDef(_) => true,
34 hir::ScopeDef::ImplSelfType(impl_) => match impl_.target_ty(ctx.db).as_adt() {
35 Some(hir::Adt::Struct(strukt)) => {
36 acc.add_struct_pat(ctx, strukt, Some(name.clone()));
37 true
38 }
39 Some(hir::Adt::Enum(_)) => !ctx.is_irrefutable_pat_binding,
40 _ => true,
41 },
34 _ => false, 42 _ => false,
35 }; 43 };
36 if add_resolution { 44 if add_resolution {
@@ -258,4 +266,24 @@ fn main() {
258"#, 266"#,
259 ); 267 );
260 } 268 }
269
270 #[test]
271 fn completes_self_pats() {
272 check_snippet(
273 r#"
274struct Foo(i32);
275impl Foo {
276 fn foo() {
277 match () {
278 $0
279 }
280 }
281}
282 "#,
283 expect![[r#"
284 bn Self Self($1)$0
285 bn Foo Foo($1)$0
286 "#]],
287 )
288 }
261} 289}