1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
//! Completions tests for pattern position.
use expect_test::{expect, Expect};
use crate::tests::completion_list;
fn check(ra_fixture: &str, expect: Expect) {
let actual = completion_list(ra_fixture);
expect.assert_eq(&actual)
}
fn check_with(ra_fixture: &str, expect: Expect) {
let base = r#"
enum Enum { TupleV(u32), RecordV { field: u32 }, UnitV }
use self::Enum::TupleV;
mod module {}
static STATIC: Unit = Unit;
const CONST: Unit = Unit;
struct Record { field: u32 }
struct Tuple(u32);
struct Unit
macro_rules! makro {}
"#;
let actual = completion_list(&format!("{}\n{}", base, ra_fixture));
expect.assert_eq(&actual)
}
#[test]
fn ident_rebind_pat() {
check(
r#"
fn quux() {
let en$0 @ x
}
"#,
expect![[r#"
kw mut
"#]],
);
}
#[test]
fn ident_ref_pat() {
check(
r#"
fn quux() {
let ref en$0
}
"#,
expect![[r#"
kw mut
"#]],
);
check(
r#"
fn quux() {
let ref en$0 @ x
}
"#,
expect![[r#"
kw mut
"#]],
);
}
#[test]
fn ident_ref_mut_pat() {
// FIXME mut is already here, don't complete it again
check(
r#"
fn quux() {
let ref mut en$0
}
"#,
expect![[r#"
kw mut
"#]],
);
check(
r#"
fn quux() {
let ref mut en$0 @ x
}
"#,
expect![[r#"
kw mut
"#]],
);
}
#[test]
fn ref_pat() {
check(
r#"
fn quux() {
let &en$0
}
"#,
expect![[r#"
kw mut
"#]],
);
// FIXME mut is already here, don't complete it again
check(
r#"
fn quux() {
let &mut en$0
}
"#,
expect![[r#"
kw mut
"#]],
);
}
#[test]
fn refutable() {
check_with(
r#"
fn foo() {
if let a$0
}
"#,
expect![[r#"
kw mut
bn Record Record { field$1 }$0
st Record
en Enum
bn Tuple Tuple($1)$0
st Tuple
md module
bn TupleV TupleV($1)$0
ev TupleV
st Unit
ct CONST
ma makro!(…) macro_rules! makro
"#]],
);
}
#[test]
fn irrefutable() {
check_with(
r#"
fn foo() {
let a$0
}
"#,
expect![[r#"
kw mut
bn Record Record { field$1 }$0
st Record
bn Tuple Tuple($1)$0
st Tuple
st Unit
ma makro!(…) macro_rules! makro
"#]],
);
}
#[test]
fn in_param() {
check_with(
r#"
fn foo(a$0) {
}
"#,
expect![[r#"
kw mut
bn Record Record { field$1 }: Record$0
st Record
bn Tuple Tuple($1): Tuple$0
st Tuple
st Unit
ma makro!(…) macro_rules! makro
"#]],
);
}
#[test]
fn only_fn_like_macros() {
check(
r#"
macro_rules! m { ($e:expr) => { $e } }
#[rustc_builtin_macro]
macro Clone {}
fn foo() {
let x$0
}
"#,
expect![[r#"
kw mut
ma m!(…) macro_rules! m
"#]],
);
}
#[test]
fn in_simple_macro_call() {
check(
r#"
macro_rules! m { ($e:expr) => { $e } }
enum E { X }
fn foo() {
m!(match E::X { a$0 })
}
"#,
expect![[r#"
kw mut
ev E::X ()
en E
ma m!(…) macro_rules! m
"#]],
);
}
#[test]
fn omits_private_fields_pat() {
check(
r#"
mod foo {
pub struct Record { pub field: i32, _field: i32 }
pub struct Tuple(pub u32, u32);
pub struct Invisible(u32, u32);
}
use foo::*;
fn outer() {
if let a$0
}
"#,
expect![[r#"
kw mut
bn Record Record { field$1, .. }$0
st Record
bn Tuple Tuple($1, ..)$0
st Tuple
st Invisible
md foo
"#]],
)
}
// #[test]
// fn only_shows_ident_completion() {
// check_edit(
// "Foo",
// r#"
// struct Foo(i32);
// fn main() {
// match Foo(92) {
// a$0(92) => (),
// }
// }
// "#,
// r#"
// struct Foo(i32);
// fn main() {
// match Foo(92) {
// Foo(92) => (),
// }
// }
// "#,
// );
// }
#[test]
fn completes_self_pats() {
check(
r#"
struct Foo(i32);
impl Foo {
fn foo() {
match Foo(0) {
a$0
}
}
}
"#,
expect![[r#"
kw mut
bn Self Self($1)$0
sp Self
bn Foo Foo($1)$0
st Foo
"#]],
)
}
#[test]
fn completes_qualified_variant() {
check(
r#"
enum Foo {
Bar { baz: i32 }
}
impl Foo {
fn foo() {
match {Foo::Bar { baz: 0 }} {
B$0
}
}
}
"#,
expect![[r#"
kw mut
bn Self::Bar Self::Bar { baz$1 }$0
ev Self::Bar { baz: i32 }
bn Foo::Bar Foo::Bar { baz$1 }$0
ev Foo::Bar { baz: i32 }
sp Self
en Foo
"#]],
)
}
#[test]
fn completes_in_record_field_pat() {
check(
r#"
struct Foo { bar: Bar }
struct Bar(u32);
fn outer(Foo { bar: $0 }: Foo) {}
"#,
expect![[r#"
kw mut
bn Foo Foo { bar$1 }$0
st Foo
bn Bar Bar($1)$0
st Bar
"#]],
)
}
#[test]
fn skips_in_record_field_pat_name() {
check(
r#"
struct Foo { bar: Bar }
struct Bar(u32);
fn outer(Foo { bar$0 }: Foo) {}
"#,
expect![[r#""#]],
)
}
|