diff options
author | Steffen Lyngbaek <[email protected]> | 2020-03-10 01:10:25 +0000 |
---|---|---|
committer | Steffen Lyngbaek <[email protected]> | 2020-03-19 21:12:00 +0000 |
commit | b6d6277362366e7ddd2b355d83227041d8b6fa12 (patch) | |
tree | fd90520d229f62aa44d1cfb817c3bf49b8566956 /crates/ra_ide/src/completion/complete_scope.rs | |
parent | 1ba03c6995015b3143a417ed07437f0c9028a97d (diff) |
Completition for type name? #3418
Iterate through TupleStructPat's until a MatchArm if
one exists. Store in a new is_pat_bind_and_path bool
and allow the `complete_scope` to find matches.
Added some tests to ensure it works in simple and nested cases.
Diffstat (limited to 'crates/ra_ide/src/completion/complete_scope.rs')
-rw-r--r-- | crates/ra_ide/src/completion/complete_scope.rs | 107 |
1 files changed, 106 insertions, 1 deletions
diff --git a/crates/ra_ide/src/completion/complete_scope.rs b/crates/ra_ide/src/completion/complete_scope.rs index 81d3cc1b6..82842e7e3 100644 --- a/crates/ra_ide/src/completion/complete_scope.rs +++ b/crates/ra_ide/src/completion/complete_scope.rs | |||
@@ -3,7 +3,7 @@ | |||
3 | use crate::completion::{CompletionContext, Completions}; | 3 | use crate::completion::{CompletionContext, Completions}; |
4 | 4 | ||
5 | pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { | 5 | pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { |
6 | if !ctx.is_trivial_path { | 6 | if !ctx.is_trivial_path && !ctx.is_pat_binding_and_path { |
7 | return; | 7 | return; |
8 | } | 8 | } |
9 | 9 | ||
@@ -21,6 +21,111 @@ mod tests { | |||
21 | } | 21 | } |
22 | 22 | ||
23 | #[test] | 23 | #[test] |
24 | fn nested_bind_pat_and_path() { | ||
25 | assert_debug_snapshot!( | ||
26 | do_reference_completion( | ||
27 | r" | ||
28 | enum First { | ||
29 | A, | ||
30 | B, | ||
31 | } | ||
32 | enum Second { | ||
33 | A(First), | ||
34 | B(First), | ||
35 | } | ||
36 | fn quux(x: Option<Option<Second>>>) { | ||
37 | match x { | ||
38 | None => (), | ||
39 | Some(Some(Second(Fi<|>))) => (), | ||
40 | } | ||
41 | } | ||
42 | " | ||
43 | ), | ||
44 | @r###" | ||
45 | [ | ||
46 | CompletionItem { | ||
47 | label: "First", | ||
48 | source_range: [363; 365), | ||
49 | delete: [363; 365), | ||
50 | insert: "First", | ||
51 | kind: Enum, | ||
52 | }, | ||
53 | CompletionItem { | ||
54 | label: "Second", | ||
55 | source_range: [363; 365), | ||
56 | delete: [363; 365), | ||
57 | insert: "Second", | ||
58 | kind: Enum, | ||
59 | }, | ||
60 | CompletionItem { | ||
61 | label: "quux(…)", | ||
62 | source_range: [363; 365), | ||
63 | delete: [363; 365), | ||
64 | insert: "quux(${1:x})$0", | ||
65 | kind: Function, | ||
66 | lookup: "quux", | ||
67 | detail: "fn quux(x: Option<Option<Second>>)", | ||
68 | }, | ||
69 | ] | ||
70 | "### | ||
71 | ); | ||
72 | } | ||
73 | |||
74 | #[test] | ||
75 | fn bind_pat_and_path() { | ||
76 | assert_debug_snapshot!( | ||
77 | do_reference_completion( | ||
78 | r" | ||
79 | enum Enum { | ||
80 | A, | ||
81 | B, | ||
82 | } | ||
83 | fn quux(x: Option<Enum>) { | ||
84 | match x { | ||
85 | None => (), | ||
86 | Some(en<|>) => (), | ||
87 | } | ||
88 | } | ||
89 | " | ||
90 | ), | ||
91 | @r###" | ||
92 | [ | ||
93 | CompletionItem { | ||
94 | label: "Enum", | ||
95 | source_range: [231; 233), | ||
96 | delete: [231; 233), | ||
97 | insert: "Enum", | ||
98 | kind: Enum, | ||
99 | }, | ||
100 | CompletionItem { | ||
101 | label: "None", | ||
102 | source_range: [231; 233), | ||
103 | delete: [231; 233), | ||
104 | insert: "None", | ||
105 | kind: Binding, | ||
106 | }, | ||
107 | CompletionItem { | ||
108 | label: "quux(…)", | ||
109 | source_range: [231; 233), | ||
110 | delete: [231; 233), | ||
111 | insert: "quux(${1:x})$0", | ||
112 | kind: Function, | ||
113 | lookup: "quux", | ||
114 | detail: "fn quux(x: Option<Enum>)", | ||
115 | }, | ||
116 | CompletionItem { | ||
117 | label: "x", | ||
118 | source_range: [231; 233), | ||
119 | delete: [231; 233), | ||
120 | insert: "x", | ||
121 | kind: Binding, | ||
122 | }, | ||
123 | ] | ||
124 | "### | ||
125 | ); | ||
126 | } | ||
127 | |||
128 | #[test] | ||
24 | fn completes_bindings_from_let() { | 129 | fn completes_bindings_from_let() { |
25 | assert_debug_snapshot!( | 130 | assert_debug_snapshot!( |
26 | do_reference_completion( | 131 | do_reference_completion( |