From ec24c090063b3b86349f7812b716412d83dad069 Mon Sep 17 00:00:00 2001 From: Steffen Lyngbaek Date: Thu, 19 Mar 2020 00:11:25 -0700 Subject: Remove const - Add test for @ matching - Address comments --- crates/ra_ide/src/completion/complete_pattern.rs | 22 ++++++++++++++++++++++ crates/ra_ide/src/completion/complete_scope.rs | 22 +++++++++++++++++++++- crates/ra_ide/src/completion/completion_context.rs | 10 +++++----- 3 files changed, 48 insertions(+), 6 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide/src/completion/complete_pattern.rs b/crates/ra_ide/src/completion/complete_pattern.rs index e8e676a4c..bc8fade6f 100644 --- a/crates/ra_ide/src/completion/complete_pattern.rs +++ b/crates/ra_ide/src/completion/complete_pattern.rs @@ -97,6 +97,13 @@ mod tests { insert: "Z", kind: Const, }, + CompletionItem { + label: "Z", + source_range: [246; 246), + delete: [246; 246), + insert: "Z", + kind: Const, + }, CompletionItem { label: "m", source_range: [246; 246), @@ -138,6 +145,21 @@ mod tests { insert: "E", kind: Enum, }, + CompletionItem { + label: "E", + source_range: [151; 151), + delete: [151; 151), + insert: "E", + kind: Enum, + }, + CompletionItem { + label: "m!", + source_range: [151; 151), + delete: [151; 151), + insert: "m!($0)", + kind: Macro, + detail: "macro_rules! m", + }, ] "###); } diff --git a/crates/ra_ide/src/completion/complete_scope.rs b/crates/ra_ide/src/completion/complete_scope.rs index 1cb2ed070..2ca552733 100644 --- a/crates/ra_ide/src/completion/complete_scope.rs +++ b/crates/ra_ide/src/completion/complete_scope.rs @@ -11,7 +11,6 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { ctx.scope().process_all_names(&mut |name, res| match (ctx.is_pat_binding_and_path, &res) { (true, ScopeDef::ModuleDef(ModuleDef::Function(..))) => (), (true, ScopeDef::ModuleDef(ModuleDef::Static(..))) => (), - (true, ScopeDef::ModuleDef(ModuleDef::Const(..))) => (), (true, ScopeDef::Local(..)) => (), _ => acc.add_resolution(ctx, name.to_string(), &res), }); @@ -27,6 +26,27 @@ mod tests { do_completion(ra_fixture, CompletionKind::Reference) } + #[test] + fn bind_pat_and_path_ignore_at() { + assert_debug_snapshot!( + do_reference_completion( + r" + enum Enum { + A, + B, + } + fn quux(x: Option) { + match x { + None => (), + Some(en<|> @ Enum::A) => (), + } + } + " + ), + @r###"[]"### + ); + } + #[test] fn bind_pat_and_path_ignore_ref() { assert_debug_snapshot!( diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 65bdac182..319e33b61 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -197,11 +197,11 @@ impl<'a> CompletionContext<'a> { self.is_pat_binding = true; } - if parent.and_then(ast::RecordFieldPatList::cast).is_none() { - let bind_pat_string = bind_pat.syntax().to_string(); - if !bind_pat_string.contains("ref ") && !bind_pat_string.contains(" @ ") { - self.is_pat_binding_and_path = true; - } + if parent.and_then(ast::RecordFieldPatList::cast).is_none() + && bind_pat.pat().is_none() + && !bind_pat.is_ref() + { + self.is_pat_binding_and_path = true; } } if is_node::(name.syntax()) { -- cgit v1.2.3