diff options
Diffstat (limited to 'crates/ra_ide/src/completion/complete_scope.rs')
-rw-r--r-- | crates/ra_ide/src/completion/complete_scope.rs | 83 |
1 files changed, 81 insertions, 2 deletions
diff --git a/crates/ra_ide/src/completion/complete_scope.rs b/crates/ra_ide/src/completion/complete_scope.rs index 81d3cc1b6..2ca552733 100644 --- a/crates/ra_ide/src/completion/complete_scope.rs +++ b/crates/ra_ide/src/completion/complete_scope.rs | |||
@@ -1,13 +1,19 @@ | |||
1 | //! Completion of names from the current scope, e.g. locals and imported items. | 1 | //! Completion of names from the current scope, e.g. locals and imported items. |
2 | 2 | ||
3 | use crate::completion::{CompletionContext, Completions}; | 3 | use crate::completion::{CompletionContext, Completions}; |
4 | use hir::{ModuleDef, ScopeDef}; | ||
4 | 5 | ||
5 | pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { | 6 | pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { |
6 | if !ctx.is_trivial_path { | 7 | if !ctx.is_trivial_path && !ctx.is_pat_binding_and_path { |
7 | return; | 8 | return; |
8 | } | 9 | } |
9 | 10 | ||
10 | ctx.scope().process_all_names(&mut |name, res| acc.add_resolution(ctx, name.to_string(), &res)); | 11 | ctx.scope().process_all_names(&mut |name, res| match (ctx.is_pat_binding_and_path, &res) { |
12 | (true, ScopeDef::ModuleDef(ModuleDef::Function(..))) => (), | ||
13 | (true, ScopeDef::ModuleDef(ModuleDef::Static(..))) => (), | ||
14 | (true, ScopeDef::Local(..)) => (), | ||
15 | _ => acc.add_resolution(ctx, name.to_string(), &res), | ||
16 | }); | ||
11 | } | 17 | } |
12 | 18 | ||
13 | #[cfg(test)] | 19 | #[cfg(test)] |
@@ -21,6 +27,79 @@ mod tests { | |||
21 | } | 27 | } |
22 | 28 | ||
23 | #[test] | 29 | #[test] |
30 | fn bind_pat_and_path_ignore_at() { | ||
31 | assert_debug_snapshot!( | ||
32 | do_reference_completion( | ||
33 | r" | ||
34 | enum Enum { | ||
35 | A, | ||
36 | B, | ||
37 | } | ||
38 | fn quux(x: Option<Enum>) { | ||
39 | match x { | ||
40 | None => (), | ||
41 | Some(en<|> @ Enum::A) => (), | ||
42 | } | ||
43 | } | ||
44 | " | ||
45 | ), | ||
46 | @r###"[]"### | ||
47 | ); | ||
48 | } | ||
49 | |||
50 | #[test] | ||
51 | fn bind_pat_and_path_ignore_ref() { | ||
52 | assert_debug_snapshot!( | ||
53 | do_reference_completion( | ||
54 | r" | ||
55 | enum Enum { | ||
56 | A, | ||
57 | B, | ||
58 | } | ||
59 | fn quux(x: Option<Enum>) { | ||
60 | match x { | ||
61 | None => (), | ||
62 | Some(ref en<|>) => (), | ||
63 | } | ||
64 | } | ||
65 | " | ||
66 | ), | ||
67 | @r###"[]"### | ||
68 | ); | ||
69 | } | ||
70 | |||
71 | #[test] | ||
72 | fn bind_pat_and_path() { | ||
73 | assert_debug_snapshot!( | ||
74 | do_reference_completion( | ||
75 | r" | ||
76 | enum Enum { | ||
77 | A, | ||
78 | B, | ||
79 | } | ||
80 | fn quux(x: Option<Enum>) { | ||
81 | match x { | ||
82 | None => (), | ||
83 | Some(En<|>) => (), | ||
84 | } | ||
85 | } | ||
86 | " | ||
87 | ), | ||
88 | @r###" | ||
89 | [ | ||
90 | CompletionItem { | ||
91 | label: "Enum", | ||
92 | source_range: [231; 233), | ||
93 | delete: [231; 233), | ||
94 | insert: "Enum", | ||
95 | kind: Enum, | ||
96 | }, | ||
97 | ] | ||
98 | "### | ||
99 | ); | ||
100 | } | ||
101 | |||
102 | #[test] | ||
24 | fn completes_bindings_from_let() { | 103 | fn completes_bindings_from_let() { |
25 | assert_debug_snapshot!( | 104 | assert_debug_snapshot!( |
26 | do_reference_completion( | 105 | do_reference_completion( |