diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-12-19 18:43:20 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-12-19 18:43:20 +0000 |
commit | 052e7227b6f7eb8dc4f689a7e14d110b8aff8555 (patch) | |
tree | 7039ea9626325051e53f38fe97b98ec4560accc5 /crates | |
parent | 8b73135b11ba241aa92ca4242166f563b42bf05d (diff) | |
parent | b45ec84739eced0d93d9ccdaa06b546a5a567dea (diff) |
Merge #6946
6946: Better fuzzy heuristics r=matklad a=SomeoneToIgnore
Continuation of the https://github.com/rust-analyzer/rust-analyzer/pull/6922, mainly created for a test.
Turns out our current completions tests were sorting the completions by label, I had to remove that to test the order properly and update this order in a bunch of tests (ergo the changes)
Co-authored-by: Kirill Bulatov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/completion/src/completions/attribute.rs | 16 | ||||
-rw-r--r-- | crates/completion/src/completions/dot.rs | 8 | ||||
-rw-r--r-- | crates/completion/src/completions/keyword.rs | 142 | ||||
-rw-r--r-- | crates/completion/src/completions/mod_.rs | 4 | ||||
-rw-r--r-- | crates/completion/src/completions/pattern.rs | 4 | ||||
-rw-r--r-- | crates/completion/src/completions/postfix.rs | 62 | ||||
-rw-r--r-- | crates/completion/src/completions/qualified_path.rs | 56 | ||||
-rw-r--r-- | crates/completion/src/completions/record.rs | 4 | ||||
-rw-r--r-- | crates/completion/src/completions/snippet.rs | 4 | ||||
-rw-r--r-- | crates/completion/src/completions/trait_impl.rs | 4 | ||||
-rw-r--r-- | crates/completion/src/completions/unqualified_path.rs | 172 | ||||
-rw-r--r-- | crates/completion/src/test_utils.rs | 3 |
12 files changed, 263 insertions, 216 deletions
diff --git a/crates/completion/src/completions/attribute.rs b/crates/completion/src/completions/attribute.rs index acce2e7e7..19ce2482f 100644 --- a/crates/completion/src/completions/attribute.rs +++ b/crates/completion/src/completions/attribute.rs | |||
@@ -428,8 +428,8 @@ struct Test {} | |||
428 | at Hash | 428 | at Hash |
429 | at PartialEq | 429 | at PartialEq |
430 | at PartialEq, Eq | 430 | at PartialEq, Eq |
431 | at PartialEq, Eq, PartialOrd, Ord | ||
432 | at PartialEq, PartialOrd | 431 | at PartialEq, PartialOrd |
432 | at PartialEq, Eq, PartialOrd, Ord | ||
433 | "#]], | 433 | "#]], |
434 | ); | 434 | ); |
435 | } | 435 | } |
@@ -457,10 +457,10 @@ struct Test {} | |||
457 | at Clone, Copy | 457 | at Clone, Copy |
458 | at Debug | 458 | at Debug |
459 | at Default | 459 | at Default |
460 | at Eq | ||
461 | at Eq, PartialOrd, Ord | ||
462 | at Hash | 460 | at Hash |
461 | at Eq | ||
463 | at PartialOrd | 462 | at PartialOrd |
463 | at Eq, PartialOrd, Ord | ||
464 | "#]], | 464 | "#]], |
465 | ) | 465 | ) |
466 | } | 466 | } |
@@ -472,14 +472,14 @@ struct Test {} | |||
472 | expect![[r#" | 472 | expect![[r#" |
473 | at allow(…) | 473 | at allow(…) |
474 | at automatically_derived | 474 | at automatically_derived |
475 | at cfg(…) | ||
476 | at cfg_attr(…) | 475 | at cfg_attr(…) |
476 | at cfg(…) | ||
477 | at cold | 477 | at cold |
478 | at deny(…) | 478 | at deny(…) |
479 | at deprecated = "…" | 479 | at deprecated = "…" |
480 | at derive(…) | 480 | at derive(…) |
481 | at doc = "…" | ||
482 | at export_name = "…" | 481 | at export_name = "…" |
482 | at doc = "…" | ||
483 | at forbid(…) | 483 | at forbid(…) |
484 | at ignore = "…" | 484 | at ignore = "…" |
485 | at inline(…) | 485 | at inline(…) |
@@ -518,15 +518,15 @@ struct Test {} | |||
518 | expect![[r#" | 518 | expect![[r#" |
519 | at allow(…) | 519 | at allow(…) |
520 | at automatically_derived | 520 | at automatically_derived |
521 | at cfg(…) | ||
522 | at cfg_attr(…) | 521 | at cfg_attr(…) |
522 | at cfg(…) | ||
523 | at cold | 523 | at cold |
524 | at crate_name = "" | 524 | at crate_name = "" |
525 | at deny(…) | 525 | at deny(…) |
526 | at deprecated = "…" | 526 | at deprecated = "…" |
527 | at derive(…) | 527 | at derive(…) |
528 | at doc = "…" | ||
529 | at export_name = "…" | 528 | at export_name = "…" |
529 | at doc = "…" | ||
530 | at feature(…) | 530 | at feature(…) |
531 | at forbid(…) | 531 | at forbid(…) |
532 | at global_allocator | 532 | at global_allocator |
@@ -538,8 +538,8 @@ struct Test {} | |||
538 | at macro_export | 538 | at macro_export |
539 | at macro_use | 539 | at macro_use |
540 | at must_use = "…" | 540 | at must_use = "…" |
541 | at no_implicit_prelude | ||
542 | at no_link | 541 | at no_link |
542 | at no_implicit_prelude | ||
543 | at no_main | 543 | at no_main |
544 | at no_mangle | 544 | at no_mangle |
545 | at no_std | 545 | at no_std |
diff --git a/crates/completion/src/completions/dot.rs b/crates/completion/src/completions/dot.rs index c9875045a..551ef1771 100644 --- a/crates/completion/src/completions/dot.rs +++ b/crates/completion/src/completions/dot.rs | |||
@@ -82,8 +82,8 @@ impl S { | |||
82 | fn foo(s: S) { s.<|> } | 82 | fn foo(s: S) { s.<|> } |
83 | "#, | 83 | "#, |
84 | expect![[r#" | 84 | expect![[r#" |
85 | me bar() fn bar(&self) | ||
86 | fd foo u32 | 85 | fd foo u32 |
86 | me bar() fn bar(&self) | ||
87 | "#]], | 87 | "#]], |
88 | ); | 88 | ); |
89 | } | 89 | } |
@@ -98,8 +98,8 @@ impl S { | |||
98 | } | 98 | } |
99 | "#, | 99 | "#, |
100 | expect![[r#" | 100 | expect![[r#" |
101 | me foo() fn foo(self) | ||
102 | fd the_field (u32,) | 101 | fd the_field (u32,) |
102 | me foo() fn foo(self) | ||
103 | "#]], | 103 | "#]], |
104 | ) | 104 | ) |
105 | } | 105 | } |
@@ -114,8 +114,8 @@ impl A { | |||
114 | } | 114 | } |
115 | "#, | 115 | "#, |
116 | expect![[r#" | 116 | expect![[r#" |
117 | me foo() fn foo(&self) | ||
118 | fd the_field (u32, i32) | 117 | fd the_field (u32, i32) |
118 | me foo() fn foo(&self) | ||
119 | "#]], | 119 | "#]], |
120 | ) | 120 | ) |
121 | } | 121 | } |
@@ -147,8 +147,8 @@ mod inner { | |||
147 | fn foo(a: inner::A) { a.<|> } | 147 | fn foo(a: inner::A) { a.<|> } |
148 | "#, | 148 | "#, |
149 | expect![[r#" | 149 | expect![[r#" |
150 | fd crate_field u32 | ||
151 | fd pub_field u32 | 150 | fd pub_field u32 |
151 | fd crate_field u32 | ||
152 | fd super_field u32 | 152 | fd super_field u32 |
153 | "#]], | 153 | "#]], |
154 | ); | 154 | ); |
diff --git a/crates/completion/src/completions/keyword.rs b/crates/completion/src/completions/keyword.rs index 720349b9d..1859dec70 100644 --- a/crates/completion/src/completions/keyword.rs +++ b/crates/completion/src/completions/keyword.rs | |||
@@ -223,21 +223,21 @@ mod tests { | |||
223 | check( | 223 | check( |
224 | r"m<|>", | 224 | r"m<|>", |
225 | expect![[r#" | 225 | expect![[r#" |
226 | kw const | ||
227 | kw enum | ||
228 | kw extern | ||
229 | kw fn | 226 | kw fn |
227 | kw use | ||
230 | kw impl | 228 | kw impl |
231 | kw mod | ||
232 | kw pub | ||
233 | kw pub(crate) | ||
234 | kw static | ||
235 | kw struct | ||
236 | kw trait | 229 | kw trait |
237 | kw type | 230 | kw enum |
231 | kw struct | ||
238 | kw union | 232 | kw union |
233 | kw mod | ||
234 | kw const | ||
235 | kw type | ||
236 | kw static | ||
237 | kw extern | ||
239 | kw unsafe | 238 | kw unsafe |
240 | kw use | 239 | kw pub(crate) |
240 | kw pub | ||
241 | "#]], | 241 | "#]], |
242 | ); | 242 | ); |
243 | } | 243 | } |
@@ -247,23 +247,23 @@ mod tests { | |||
247 | check( | 247 | check( |
248 | r"fn quux() { <|> }", | 248 | r"fn quux() { <|> }", |
249 | expect![[r#" | 249 | expect![[r#" |
250 | kw const | ||
251 | kw extern | ||
252 | kw fn | 250 | kw fn |
251 | kw use | ||
252 | kw impl | ||
253 | kw trait | ||
254 | kw match | ||
255 | kw while | ||
256 | kw loop | ||
253 | kw if | 257 | kw if |
254 | kw if let | 258 | kw if let |
255 | kw impl | ||
256 | kw let | 259 | kw let |
257 | kw loop | ||
258 | kw match | ||
259 | kw mod | 260 | kw mod |
260 | kw return | 261 | kw const |
261 | kw static | ||
262 | kw trait | ||
263 | kw type | 262 | kw type |
263 | kw static | ||
264 | kw extern | ||
264 | kw unsafe | 265 | kw unsafe |
265 | kw use | 266 | kw return |
266 | kw while | ||
267 | "#]], | 267 | "#]], |
268 | ); | 268 | ); |
269 | } | 269 | } |
@@ -273,23 +273,23 @@ mod tests { | |||
273 | check( | 273 | check( |
274 | r"fn quux() { if true { <|> } }", | 274 | r"fn quux() { if true { <|> } }", |
275 | expect![[r#" | 275 | expect![[r#" |
276 | kw const | ||
277 | kw extern | ||
278 | kw fn | 276 | kw fn |
277 | kw use | ||
278 | kw impl | ||
279 | kw trait | ||
280 | kw match | ||
281 | kw while | ||
282 | kw loop | ||
279 | kw if | 283 | kw if |
280 | kw if let | 284 | kw if let |
281 | kw impl | ||
282 | kw let | 285 | kw let |
283 | kw loop | ||
284 | kw match | ||
285 | kw mod | 286 | kw mod |
286 | kw return | 287 | kw const |
287 | kw static | ||
288 | kw trait | ||
289 | kw type | 288 | kw type |
289 | kw static | ||
290 | kw extern | ||
290 | kw unsafe | 291 | kw unsafe |
291 | kw use | 292 | kw return |
292 | kw while | ||
293 | "#]], | 293 | "#]], |
294 | ); | 294 | ); |
295 | } | 295 | } |
@@ -299,25 +299,25 @@ mod tests { | |||
299 | check( | 299 | check( |
300 | r#"fn quux() { if true { () } <|> }"#, | 300 | r#"fn quux() { if true { () } <|> }"#, |
301 | expect![[r#" | 301 | expect![[r#" |
302 | kw const | ||
303 | kw else | ||
304 | kw else if | ||
305 | kw extern | ||
306 | kw fn | 302 | kw fn |
303 | kw use | ||
304 | kw impl | ||
305 | kw trait | ||
306 | kw match | ||
307 | kw while | ||
308 | kw loop | ||
307 | kw if | 309 | kw if |
308 | kw if let | 310 | kw if let |
309 | kw impl | ||
310 | kw let | 311 | kw let |
311 | kw loop | 312 | kw else |
312 | kw match | 313 | kw else if |
313 | kw mod | 314 | kw mod |
314 | kw return | 315 | kw const |
315 | kw static | ||
316 | kw trait | ||
317 | kw type | 316 | kw type |
317 | kw static | ||
318 | kw extern | ||
318 | kw unsafe | 319 | kw unsafe |
319 | kw use | 320 | kw return |
320 | kw while | ||
321 | "#]], | 321 | "#]], |
322 | ); | 322 | ); |
323 | check_edit( | 323 | check_edit( |
@@ -336,13 +336,13 @@ fn quux() -> i32 { | |||
336 | } | 336 | } |
337 | "#, | 337 | "#, |
338 | expect![[r#" | 338 | expect![[r#" |
339 | kw match | ||
340 | kw while | ||
341 | kw loop | ||
339 | kw if | 342 | kw if |
340 | kw if let | 343 | kw if let |
341 | kw loop | ||
342 | kw match | ||
343 | kw return | ||
344 | kw unsafe | 344 | kw unsafe |
345 | kw while | 345 | kw return |
346 | "#]], | 346 | "#]], |
347 | ); | 347 | ); |
348 | } | 348 | } |
@@ -352,8 +352,8 @@ fn quux() -> i32 { | |||
352 | check( | 352 | check( |
353 | r"trait My { <|> }", | 353 | r"trait My { <|> }", |
354 | expect![[r#" | 354 | expect![[r#" |
355 | kw const | ||
356 | kw fn | 355 | kw fn |
356 | kw const | ||
357 | kw type | 357 | kw type |
358 | kw unsafe | 358 | kw unsafe |
359 | "#]], | 359 | "#]], |
@@ -365,12 +365,12 @@ fn quux() -> i32 { | |||
365 | check( | 365 | check( |
366 | r"impl My { <|> }", | 366 | r"impl My { <|> }", |
367 | expect![[r#" | 367 | expect![[r#" |
368 | kw const | ||
369 | kw fn | 368 | kw fn |
370 | kw pub | 369 | kw const |
371 | kw pub(crate) | ||
372 | kw type | 370 | kw type |
373 | kw unsafe | 371 | kw unsafe |
372 | kw pub(crate) | ||
373 | kw pub | ||
374 | "#]], | 374 | "#]], |
375 | ); | 375 | ); |
376 | } | 376 | } |
@@ -380,25 +380,25 @@ fn quux() -> i32 { | |||
380 | check( | 380 | check( |
381 | r"fn my() { loop { <|> } }", | 381 | r"fn my() { loop { <|> } }", |
382 | expect![[r#" | 382 | expect![[r#" |
383 | kw break | ||
384 | kw const | ||
385 | kw continue | ||
386 | kw extern | ||
387 | kw fn | 383 | kw fn |
384 | kw use | ||
385 | kw impl | ||
386 | kw trait | ||
387 | kw match | ||
388 | kw while | ||
389 | kw loop | ||
388 | kw if | 390 | kw if |
389 | kw if let | 391 | kw if let |
390 | kw impl | ||
391 | kw let | 392 | kw let |
392 | kw loop | ||
393 | kw match | ||
394 | kw mod | 393 | kw mod |
395 | kw return | 394 | kw const |
396 | kw static | ||
397 | kw trait | ||
398 | kw type | 395 | kw type |
396 | kw static | ||
397 | kw extern | ||
399 | kw unsafe | 398 | kw unsafe |
400 | kw use | 399 | kw continue |
401 | kw while | 400 | kw break |
401 | kw return | ||
402 | "#]], | 402 | "#]], |
403 | ); | 403 | ); |
404 | } | 404 | } |
@@ -409,8 +409,8 @@ fn quux() -> i32 { | |||
409 | r"unsafe <|>", | 409 | r"unsafe <|>", |
410 | expect![[r#" | 410 | expect![[r#" |
411 | kw fn | 411 | kw fn |
412 | kw impl | ||
413 | kw trait | 412 | kw trait |
413 | kw impl | ||
414 | "#]], | 414 | "#]], |
415 | ); | 415 | ); |
416 | } | 416 | } |
@@ -421,8 +421,8 @@ fn quux() -> i32 { | |||
421 | r"fn my_fn() { unsafe <|> }", | 421 | r"fn my_fn() { unsafe <|> }", |
422 | expect![[r#" | 422 | expect![[r#" |
423 | kw fn | 423 | kw fn |
424 | kw impl | ||
425 | kw trait | 424 | kw trait |
425 | kw impl | ||
426 | "#]], | 426 | "#]], |
427 | ); | 427 | ); |
428 | } | 428 | } |
@@ -542,12 +542,12 @@ pub mod future { | |||
542 | check( | 542 | check( |
543 | r#"fn main() { let _ = <|> }"#, | 543 | r#"fn main() { let _ = <|> }"#, |
544 | expect![[r#" | 544 | expect![[r#" |
545 | kw match | ||
546 | kw while | ||
547 | kw loop | ||
545 | kw if | 548 | kw if |
546 | kw if let | 549 | kw if let |
547 | kw loop | ||
548 | kw match | ||
549 | kw return | 550 | kw return |
550 | kw while | ||
551 | "#]], | 551 | "#]], |
552 | ) | 552 | ) |
553 | } | 553 | } |
@@ -562,8 +562,8 @@ struct Foo { | |||
562 | } | 562 | } |
563 | "#, | 563 | "#, |
564 | expect![[r#" | 564 | expect![[r#" |
565 | kw pub | ||
566 | kw pub(crate) | 565 | kw pub(crate) |
566 | kw pub | ||
567 | "#]], | 567 | "#]], |
568 | ) | 568 | ) |
569 | } | 569 | } |
@@ -600,12 +600,12 @@ fn foo() { | |||
600 | } | 600 | } |
601 | "#, | 601 | "#, |
602 | expect![[r#" | 602 | expect![[r#" |
603 | kw match | ||
604 | kw while | ||
605 | kw loop | ||
603 | kw if | 606 | kw if |
604 | kw if let | 607 | kw if let |
605 | kw loop | ||
606 | kw match | ||
607 | kw return | 608 | kw return |
608 | kw while | ||
609 | "#]], | 609 | "#]], |
610 | ); | 610 | ); |
611 | } | 611 | } |
diff --git a/crates/completion/src/completions/mod_.rs b/crates/completion/src/completions/mod_.rs index c96f84171..f77864b77 100644 --- a/crates/completion/src/completions/mod_.rs +++ b/crates/completion/src/completions/mod_.rs | |||
@@ -170,8 +170,8 @@ mod tests { | |||
170 | fn ignored_bar() {} | 170 | fn ignored_bar() {} |
171 | "#, | 171 | "#, |
172 | expect![[r#" | 172 | expect![[r#" |
173 | md bar; | ||
174 | md foo; | 173 | md foo; |
174 | md bar; | ||
175 | "#]], | 175 | "#]], |
176 | ); | 176 | ); |
177 | } | 177 | } |
@@ -207,8 +207,8 @@ mod tests { | |||
207 | fn ignored_bar() {} | 207 | fn ignored_bar() {} |
208 | "#, | 208 | "#, |
209 | expect![[r#" | 209 | expect![[r#" |
210 | md bar; | ||
211 | md foo; | 210 | md foo; |
211 | md bar; | ||
212 | "#]], | 212 | "#]], |
213 | ); | 213 | ); |
214 | } | 214 | } |
diff --git a/crates/completion/src/completions/pattern.rs b/crates/completion/src/completions/pattern.rs index 4f63ff0ef..0c98e4412 100644 --- a/crates/completion/src/completions/pattern.rs +++ b/crates/completion/src/completions/pattern.rs | |||
@@ -66,10 +66,10 @@ fn foo() { | |||
66 | } | 66 | } |
67 | "#, | 67 | "#, |
68 | expect![[r#" | 68 | expect![[r#" |
69 | st Bar | ||
70 | en E | 69 | en E |
71 | ev X () | ||
72 | ct Z | 70 | ct Z |
71 | st Bar | ||
72 | ev X () | ||
73 | md m | 73 | md m |
74 | "#]], | 74 | "#]], |
75 | ); | 75 | ); |
diff --git a/crates/completion/src/completions/postfix.rs b/crates/completion/src/completions/postfix.rs index c8ba63cd3..d6db82a93 100644 --- a/crates/completion/src/completions/postfix.rs +++ b/crates/completion/src/completions/postfix.rs | |||
@@ -315,20 +315,20 @@ fn main() { | |||
315 | } | 315 | } |
316 | "#, | 316 | "#, |
317 | expect![[r#" | 317 | expect![[r#" |
318 | sn box Box::new(expr) | ||
319 | sn call function(expr) | ||
320 | sn dbg dbg!(expr) | ||
321 | sn dbgr dbg!(&expr) | ||
322 | sn if if expr {} | 318 | sn if if expr {} |
323 | sn let let | 319 | sn while while expr {} |
324 | sn letm let mut | ||
325 | sn match match expr {} | ||
326 | sn not !expr | 320 | sn not !expr |
327 | sn ok Ok(expr) | ||
328 | sn ref &expr | 321 | sn ref &expr |
329 | sn refm &mut expr | 322 | sn refm &mut expr |
323 | sn match match expr {} | ||
324 | sn box Box::new(expr) | ||
325 | sn ok Ok(expr) | ||
330 | sn some Some(expr) | 326 | sn some Some(expr) |
331 | sn while while expr {} | 327 | sn dbg dbg!(expr) |
328 | sn dbgr dbg!(&expr) | ||
329 | sn call function(expr) | ||
330 | sn let let | ||
331 | sn letm let mut | ||
332 | "#]], | 332 | "#]], |
333 | ); | 333 | ); |
334 | } | 334 | } |
@@ -347,18 +347,18 @@ fn main() { | |||
347 | } | 347 | } |
348 | "#, | 348 | "#, |
349 | expect![[r#" | 349 | expect![[r#" |
350 | sn box Box::new(expr) | ||
351 | sn call function(expr) | ||
352 | sn dbg dbg!(expr) | ||
353 | sn dbgr dbg!(&expr) | ||
354 | sn if if expr {} | 350 | sn if if expr {} |
355 | sn match match expr {} | 351 | sn while while expr {} |
356 | sn not !expr | 352 | sn not !expr |
357 | sn ok Ok(expr) | ||
358 | sn ref &expr | 353 | sn ref &expr |
359 | sn refm &mut expr | 354 | sn refm &mut expr |
355 | sn match match expr {} | ||
356 | sn box Box::new(expr) | ||
357 | sn ok Ok(expr) | ||
360 | sn some Some(expr) | 358 | sn some Some(expr) |
361 | sn while while expr {} | 359 | sn dbg dbg!(expr) |
360 | sn dbgr dbg!(&expr) | ||
361 | sn call function(expr) | ||
362 | "#]], | 362 | "#]], |
363 | ); | 363 | ); |
364 | } | 364 | } |
@@ -373,17 +373,17 @@ fn main() { | |||
373 | } | 373 | } |
374 | "#, | 374 | "#, |
375 | expect![[r#" | 375 | expect![[r#" |
376 | sn ref &expr | ||
377 | sn refm &mut expr | ||
378 | sn match match expr {} | ||
376 | sn box Box::new(expr) | 379 | sn box Box::new(expr) |
377 | sn call function(expr) | 380 | sn ok Ok(expr) |
381 | sn some Some(expr) | ||
378 | sn dbg dbg!(expr) | 382 | sn dbg dbg!(expr) |
379 | sn dbgr dbg!(&expr) | 383 | sn dbgr dbg!(&expr) |
384 | sn call function(expr) | ||
380 | sn let let | 385 | sn let let |
381 | sn letm let mut | 386 | sn letm let mut |
382 | sn match match expr {} | ||
383 | sn ok Ok(expr) | ||
384 | sn ref &expr | ||
385 | sn refm &mut expr | ||
386 | sn some Some(expr) | ||
387 | "#]], | 387 | "#]], |
388 | ) | 388 | ) |
389 | } | 389 | } |
@@ -398,20 +398,20 @@ fn main() { | |||
398 | } | 398 | } |
399 | "#, | 399 | "#, |
400 | expect![[r#" | 400 | expect![[r#" |
401 | sn box Box::new(expr) | ||
402 | sn call function(expr) | ||
403 | sn dbg dbg!(expr) | ||
404 | sn dbgr dbg!(&expr) | ||
405 | sn if if expr {} | 401 | sn if if expr {} |
406 | sn let let | 402 | sn while while expr {} |
407 | sn letm let mut | ||
408 | sn match match expr {} | ||
409 | sn not !expr | 403 | sn not !expr |
410 | sn ok Ok(expr) | ||
411 | sn ref &expr | 404 | sn ref &expr |
412 | sn refm &mut expr | 405 | sn refm &mut expr |
406 | sn match match expr {} | ||
407 | sn box Box::new(expr) | ||
408 | sn ok Ok(expr) | ||
413 | sn some Some(expr) | 409 | sn some Some(expr) |
414 | sn while while expr {} | 410 | sn dbg dbg!(expr) |
411 | sn dbgr dbg!(&expr) | ||
412 | sn call function(expr) | ||
413 | sn let let | ||
414 | sn letm let mut | ||
415 | "#]], | 415 | "#]], |
416 | ); | 416 | ); |
417 | } | 417 | } |
diff --git a/crates/completion/src/completions/qualified_path.rs b/crates/completion/src/completions/qualified_path.rs index bc23bea3f..1300f00b2 100644 --- a/crates/completion/src/completions/qualified_path.rs +++ b/crates/completion/src/completions/qualified_path.rs | |||
@@ -199,22 +199,22 @@ use self::{foo::*, bar<|>}; | |||
199 | check_builtin( | 199 | check_builtin( |
200 | r#"fn main() { let _: <|> = 92; }"#, | 200 | r#"fn main() { let _: <|> = 92; }"#, |
201 | expect![[r#" | 201 | expect![[r#" |
202 | bt u32 | ||
202 | bt bool | 203 | bt bool |
203 | bt char | 204 | bt u8 |
205 | bt isize | ||
206 | bt u16 | ||
207 | bt u64 | ||
208 | bt u128 | ||
204 | bt f32 | 209 | bt f32 |
205 | bt f64 | ||
206 | bt i128 | 210 | bt i128 |
207 | bt i16 | 211 | bt i16 |
208 | bt i32 | 212 | bt str |
209 | bt i64 | 213 | bt i64 |
214 | bt char | ||
215 | bt f64 | ||
216 | bt i32 | ||
210 | bt i8 | 217 | bt i8 |
211 | bt isize | ||
212 | bt str | ||
213 | bt u128 | ||
214 | bt u16 | ||
215 | bt u32 | ||
216 | bt u64 | ||
217 | bt u8 | ||
218 | bt usize | 218 | bt usize |
219 | "#]], | 219 | "#]], |
220 | ); | 220 | ); |
@@ -279,8 +279,8 @@ struct Spam; | |||
279 | use crate::Sp<|> | 279 | use crate::Sp<|> |
280 | "#, | 280 | "#, |
281 | expect![[r#" | 281 | expect![[r#" |
282 | st Spam | ||
283 | md foo | 282 | md foo |
283 | st Spam | ||
284 | "#]], | 284 | "#]], |
285 | ); | 285 | ); |
286 | } | 286 | } |
@@ -296,8 +296,8 @@ struct Spam; | |||
296 | use crate::{Sp<|>}; | 296 | use crate::{Sp<|>}; |
297 | "#, | 297 | "#, |
298 | expect![[r#" | 298 | expect![[r#" |
299 | st Spam | ||
300 | md foo | 299 | md foo |
300 | st Spam | ||
301 | "#]], | 301 | "#]], |
302 | ); | 302 | ); |
303 | } | 303 | } |
@@ -330,8 +330,8 @@ enum E { Foo, Bar(i32) } | |||
330 | fn foo() { let _ = E::<|> } | 330 | fn foo() { let _ = E::<|> } |
331 | "#, | 331 | "#, |
332 | expect![[r#" | 332 | expect![[r#" |
333 | ev Bar(…) (i32) | ||
334 | ev Foo () | 333 | ev Foo () |
334 | ev Bar(…) (i32) | ||
335 | "#]], | 335 | "#]], |
336 | ); | 336 | ); |
337 | } | 337 | } |
@@ -353,10 +353,10 @@ impl S { | |||
353 | fn foo() { let _ = S::<|> } | 353 | fn foo() { let _ = S::<|> } |
354 | "#, | 354 | "#, |
355 | expect![[r#" | 355 | expect![[r#" |
356 | ct C const C: i32 = 42; | ||
357 | ta T type T = i32; | ||
358 | fn a() fn a() | 356 | fn a() fn a() |
359 | me b(…) fn b(&self) | 357 | me b(…) fn b(&self) |
358 | ct C const C: i32 = 42; | ||
359 | ta T type T = i32; | ||
360 | "#]], | 360 | "#]], |
361 | ); | 361 | ); |
362 | } | 362 | } |
@@ -381,9 +381,9 @@ mod m { | |||
381 | fn foo() { let _ = S::<|> } | 381 | fn foo() { let _ = S::<|> } |
382 | "#, | 382 | "#, |
383 | expect![[r#" | 383 | expect![[r#" |
384 | fn public_method() pub(crate) fn public_method() | ||
384 | ct PUBLIC_CONST pub(crate) const PUBLIC_CONST: u32 = 1; | 385 | ct PUBLIC_CONST pub(crate) const PUBLIC_CONST: u32 = 1; |
385 | ta PublicType pub(crate) type PublicType = u32; | 386 | ta PublicType pub(crate) type PublicType = u32; |
386 | fn public_method() pub(crate) fn public_method() | ||
387 | "#]], | 387 | "#]], |
388 | ); | 388 | ); |
389 | } | 389 | } |
@@ -503,14 +503,14 @@ trait Sub: Super { | |||
503 | fn foo<T: Sub>() { T::<|> } | 503 | fn foo<T: Sub>() { T::<|> } |
504 | "#, | 504 | "#, |
505 | expect![[r#" | 505 | expect![[r#" |
506 | ct C2 const C2: (); | ||
507 | ct CONST const CONST: u8; | ||
508 | ta SubTy type SubTy; | 506 | ta SubTy type SubTy; |
509 | ta Ty type Ty; | 507 | ta Ty type Ty; |
510 | fn func() fn func() | 508 | ct C2 const C2: (); |
511 | me method(…) fn method(&self) | ||
512 | fn subfunc() fn subfunc() | 509 | fn subfunc() fn subfunc() |
513 | me submethod(…) fn submethod(&self) | 510 | me submethod(…) fn submethod(&self) |
511 | ct CONST const CONST: u8; | ||
512 | fn func() fn func() | ||
513 | me method(…) fn method(&self) | ||
514 | "#]], | 514 | "#]], |
515 | ); | 515 | ); |
516 | } | 516 | } |
@@ -543,12 +543,12 @@ impl<T> Sub for Wrap<T> { | |||
543 | } | 543 | } |
544 | "#, | 544 | "#, |
545 | expect![[r#" | 545 | expect![[r#" |
546 | ct C2 const C2: () = (); | ||
547 | ct CONST const CONST: u8 = 0; | ||
548 | ta SubTy type SubTy; | 546 | ta SubTy type SubTy; |
549 | ta Ty type Ty; | 547 | ta Ty type Ty; |
548 | ct CONST const CONST: u8 = 0; | ||
550 | fn func() fn func() | 549 | fn func() fn func() |
551 | me method(…) fn method(&self) | 550 | me method(…) fn method(&self) |
551 | ct C2 const C2: () = (); | ||
552 | fn subfunc() fn subfunc() | 552 | fn subfunc() fn subfunc() |
553 | me submethod(…) fn submethod(&self) | 553 | me submethod(…) fn submethod(&self) |
554 | "#]], | 554 | "#]], |
@@ -567,8 +567,8 @@ impl T { fn bar() {} } | |||
567 | fn main() { T::<|>; } | 567 | fn main() { T::<|>; } |
568 | "#, | 568 | "#, |
569 | expect![[r#" | 569 | expect![[r#" |
570 | fn bar() fn bar() | ||
571 | fn foo() fn foo() | 570 | fn foo() fn foo() |
571 | fn bar() fn bar() | ||
572 | "#]], | 572 | "#]], |
573 | ); | 573 | ); |
574 | } | 574 | } |
@@ -583,9 +583,9 @@ macro_rules! foo { () => {} } | |||
583 | fn main() { let _ = crate::<|> } | 583 | fn main() { let _ = crate::<|> } |
584 | "#, | 584 | "#, |
585 | expect![[r##" | 585 | expect![[r##" |
586 | fn main() fn main() | ||
586 | ma foo!(…) #[macro_export] | 587 | ma foo!(…) #[macro_export] |
587 | macro_rules! foo | 588 | macro_rules! foo |
588 | fn main() fn main() | ||
589 | "##]], | 589 | "##]], |
590 | ); | 590 | ); |
591 | } | 591 | } |
@@ -603,8 +603,8 @@ mod a { | |||
603 | } | 603 | } |
604 | "#, | 604 | "#, |
605 | expect![[r#" | 605 | expect![[r#" |
606 | ct A | ||
607 | md b | 606 | md b |
607 | ct A | ||
608 | "#]], | 608 | "#]], |
609 | ); | 609 | ); |
610 | } | 610 | } |
@@ -628,8 +628,8 @@ mod p { | |||
628 | "#, | 628 | "#, |
629 | expect![[r#" | 629 | expect![[r#" |
630 | ct RIGHT_CONST | 630 | ct RIGHT_CONST |
631 | st RightType | ||
632 | fn right_fn() fn wrong_fn() | 631 | fn right_fn() fn wrong_fn() |
632 | st RightType | ||
633 | "#]], | 633 | "#]], |
634 | ); | 634 | ); |
635 | 635 | ||
@@ -675,8 +675,8 @@ fn main() { m!(self::f<|>); } | |||
675 | fn foo() {} | 675 | fn foo() {} |
676 | "#, | 676 | "#, |
677 | expect![[r#" | 677 | expect![[r#" |
678 | fn foo() fn foo() | ||
679 | fn main() fn main() | 678 | fn main() fn main() |
679 | fn foo() fn foo() | ||
680 | "#]], | 680 | "#]], |
681 | ); | 681 | ); |
682 | } | 682 | } |
@@ -747,8 +747,8 @@ fn main() { | |||
747 | } | 747 | } |
748 | "#, | 748 | "#, |
749 | expect![[r#" | 749 | expect![[r#" |
750 | fn foo(…) fn foo(a: i32, b: i32) | ||
751 | fn main() fn main() | 750 | fn main() fn main() |
751 | fn foo(…) fn foo(a: i32, b: i32) | ||
752 | "#]], | 752 | "#]], |
753 | ); | 753 | ); |
754 | } | 754 | } |
diff --git a/crates/completion/src/completions/record.rs b/crates/completion/src/completions/record.rs index eaa44c97d..91bf4a8ad 100644 --- a/crates/completion/src/completions/record.rs +++ b/crates/completion/src/completions/record.rs | |||
@@ -94,9 +94,9 @@ fn process(f: S) { | |||
94 | check_snippet( | 94 | check_snippet( |
95 | test_code, | 95 | test_code, |
96 | expect![[r#" | 96 | expect![[r#" |
97 | fd ..Default::default() | ||
98 | sn pd | 97 | sn pd |
99 | sn ppd | 98 | sn ppd |
99 | fd ..Default::default() | ||
100 | "#]], | 100 | "#]], |
101 | ); | 101 | ); |
102 | } | 102 | } |
@@ -160,8 +160,8 @@ fn process(e: E) { | |||
160 | } | 160 | } |
161 | "#, | 161 | "#, |
162 | expect![[r#" | 162 | expect![[r#" |
163 | fd bar () | ||
164 | fd foo u32 | 163 | fd foo u32 |
164 | fd bar () | ||
165 | "#]], | 165 | "#]], |
166 | ); | 166 | ); |
167 | } | 167 | } |
diff --git a/crates/completion/src/completions/snippet.rs b/crates/completion/src/completions/snippet.rs index 6f0c00078..842590130 100644 --- a/crates/completion/src/completions/snippet.rs +++ b/crates/completion/src/completions/snippet.rs | |||
@@ -105,9 +105,9 @@ mod tests { | |||
105 | } | 105 | } |
106 | "#, | 106 | "#, |
107 | expect![[r#" | 107 | expect![[r#" |
108 | sn macro_rules | ||
109 | sn tfn (Test function) | ||
110 | sn tmod (Test module) | 108 | sn tmod (Test module) |
109 | sn tfn (Test function) | ||
110 | sn macro_rules | ||
111 | "#]], | 111 | "#]], |
112 | ) | 112 | ) |
113 | } | 113 | } |
diff --git a/crates/completion/src/completions/trait_impl.rs b/crates/completion/src/completions/trait_impl.rs index e2fe44aff..c4e0d0669 100644 --- a/crates/completion/src/completions/trait_impl.rs +++ b/crates/completion/src/completions/trait_impl.rs | |||
@@ -266,10 +266,10 @@ impl Test for T { | |||
266 | } | 266 | } |
267 | "#, | 267 | "#, |
268 | expect![[" | 268 | expect![[" |
269 | ta type TestType = \n\ | ||
269 | ct const TEST_CONST: u16 = \n\ | 270 | ct const TEST_CONST: u16 = \n\ |
270 | fn fn test() | 271 | fn fn test() |
271 | ta type TestType = \n\ | 272 | "]], |
272 | "]], | ||
273 | ); | 273 | ); |
274 | } | 274 | } |
275 | 275 | ||
diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs index 93869f92e..099ffb4d4 100644 --- a/crates/completion/src/completions/unqualified_path.rs +++ b/crates/completion/src/completions/unqualified_path.rs | |||
@@ -1,7 +1,7 @@ | |||
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 either::Either; | 3 | use either::Either; |
4 | use hir::{Adt, ModuleDef, ScopeDef, Type}; | 4 | use hir::{Adt, ModPath, ModuleDef, ScopeDef, Type}; |
5 | use ide_db::helpers::insert_use::ImportScope; | 5 | use ide_db::helpers::insert_use::ImportScope; |
6 | use ide_db::imports_locator; | 6 | use ide_db::imports_locator; |
7 | use syntax::AstNode; | 7 | use syntax::AstNode; |
@@ -146,13 +146,9 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<() | |||
146 | .filter(|(mod_path, _)| mod_path.len() > 1) | 146 | .filter(|(mod_path, _)| mod_path.len() > 1) |
147 | .collect::<Vec<_>>(); | 147 | .collect::<Vec<_>>(); |
148 | 148 | ||
149 | let user_input_lowercased = potential_import_name.to_lowercase(); | ||
149 | all_mod_paths.sort_by_cached_key(|(mod_path, _)| { | 150 | all_mod_paths.sort_by_cached_key(|(mod_path, _)| { |
150 | if let Some(name) = mod_path.segments.last().map(|name| name.to_string().to_lowercase()) { | 151 | compute_fuzzy_completion_order_key(mod_path, &user_input_lowercased) |
151 | if name.contains(&potential_import_name.to_lowercase()) { | ||
152 | return 0; | ||
153 | } | ||
154 | } | ||
155 | 1 | ||
156 | }); | 152 | }); |
157 | 153 | ||
158 | acc.add_all(all_mod_paths.into_iter().filter_map(|(import_path, definition)| { | 154 | acc.add_all(all_mod_paths.into_iter().filter_map(|(import_path, definition)| { |
@@ -165,21 +161,48 @@ fn fuzzy_completion(acc: &mut Completions, ctx: &CompletionContext) -> Option<() | |||
165 | Some(()) | 161 | Some(()) |
166 | } | 162 | } |
167 | 163 | ||
164 | fn compute_fuzzy_completion_order_key( | ||
165 | proposed_mod_path: &ModPath, | ||
166 | user_input_lowercased: &str, | ||
167 | ) -> usize { | ||
168 | mark::hit!(certain_fuzzy_order_test); | ||
169 | let proposed_import_name = match proposed_mod_path.segments.last() { | ||
170 | Some(name) => name.to_string().to_lowercase(), | ||
171 | None => return usize::MAX, | ||
172 | }; | ||
173 | match proposed_import_name.match_indices(user_input_lowercased).next() { | ||
174 | Some((first_matching_index, _)) => first_matching_index, | ||
175 | None => usize::MAX, | ||
176 | } | ||
177 | } | ||
178 | |||
168 | #[cfg(test)] | 179 | #[cfg(test)] |
169 | mod tests { | 180 | mod tests { |
170 | use expect_test::{expect, Expect}; | 181 | use expect_test::{expect, Expect}; |
171 | use test_utils::mark; | 182 | use test_utils::mark; |
172 | 183 | ||
173 | use crate::{ | 184 | use crate::{ |
174 | test_utils::{check_edit, check_edit_with_config, completion_list}, | 185 | test_utils::{check_edit, check_edit_with_config, completion_list_with_config}, |
175 | CompletionConfig, CompletionKind, | 186 | CompletionConfig, CompletionKind, |
176 | }; | 187 | }; |
177 | 188 | ||
178 | fn check(ra_fixture: &str, expect: Expect) { | 189 | fn check(ra_fixture: &str, expect: Expect) { |
179 | let actual = completion_list(ra_fixture, CompletionKind::Reference); | 190 | check_with_config(CompletionConfig::default(), ra_fixture, expect); |
191 | } | ||
192 | |||
193 | fn check_with_config(config: CompletionConfig, ra_fixture: &str, expect: Expect) { | ||
194 | let actual = completion_list_with_config(config, ra_fixture, CompletionKind::Reference); | ||
180 | expect.assert_eq(&actual) | 195 | expect.assert_eq(&actual) |
181 | } | 196 | } |
182 | 197 | ||
198 | fn fuzzy_completion_config() -> CompletionConfig { | ||
199 | let mut completion_config = CompletionConfig::default(); | ||
200 | completion_config | ||
201 | .active_resolve_capabilities | ||
202 | .insert(crate::CompletionResolveCapability::AdditionalTextEdits); | ||
203 | completion_config | ||
204 | } | ||
205 | |||
183 | #[test] | 206 | #[test] |
184 | fn self_fulfilling_completion() { | 207 | fn self_fulfilling_completion() { |
185 | mark::check!(self_fulfilling_completion); | 208 | mark::check!(self_fulfilling_completion); |
@@ -255,9 +278,9 @@ fn quux(x: i32) { | |||
255 | } | 278 | } |
256 | "#, | 279 | "#, |
257 | expect![[r#" | 280 | expect![[r#" |
258 | fn quux(…) fn quux(x: i32) | ||
259 | bn x i32 | ||
260 | bn y i32 | 281 | bn y i32 |
282 | bn x i32 | ||
283 | fn quux(…) fn quux(x: i32) | ||
261 | "#]], | 284 | "#]], |
262 | ); | 285 | ); |
263 | } | 286 | } |
@@ -277,8 +300,8 @@ fn quux() { | |||
277 | } | 300 | } |
278 | "#, | 301 | "#, |
279 | expect![[r#" | 302 | expect![[r#" |
280 | bn a | ||
281 | bn b i32 | 303 | bn b i32 |
304 | bn a | ||
282 | fn quux() fn quux() | 305 | fn quux() fn quux() |
283 | "#]], | 306 | "#]], |
284 | ); | 307 | ); |
@@ -293,8 +316,8 @@ fn quux() { | |||
293 | } | 316 | } |
294 | "#, | 317 | "#, |
295 | expect![[r#" | 318 | expect![[r#" |
296 | fn quux() fn quux() | ||
297 | bn x | 319 | bn x |
320 | fn quux() fn quux() | ||
298 | "#]], | 321 | "#]], |
299 | ); | 322 | ); |
300 | } | 323 | } |
@@ -335,9 +358,9 @@ fn main() { | |||
335 | check( | 358 | check( |
336 | r#"struct S<T> { x: <|>}"#, | 359 | r#"struct S<T> { x: <|>}"#, |
337 | expect![[r#" | 360 | expect![[r#" |
338 | st S<…> | ||
339 | tp Self | 361 | tp Self |
340 | tp T | 362 | tp T |
363 | st S<…> | ||
341 | "#]], | 364 | "#]], |
342 | ); | 365 | ); |
343 | } | 366 | } |
@@ -362,9 +385,9 @@ enum E {} | |||
362 | fn quux() { <|> } | 385 | fn quux() { <|> } |
363 | "#, | 386 | "#, |
364 | expect![[r#" | 387 | expect![[r#" |
365 | en E | ||
366 | st S | 388 | st S |
367 | fn quux() fn quux() | 389 | fn quux() fn quux() |
390 | en E | ||
368 | "#]], | 391 | "#]], |
369 | ); | 392 | ); |
370 | } | 393 | } |
@@ -416,8 +439,8 @@ mod m { | |||
416 | } | 439 | } |
417 | "#, | 440 | "#, |
418 | expect![[r#" | 441 | expect![[r#" |
419 | st Bar | ||
420 | fn quux() fn quux() | 442 | fn quux() fn quux() |
443 | st Bar | ||
421 | "#]], | 444 | "#]], |
422 | ); | 445 | ); |
423 | } | 446 | } |
@@ -462,8 +485,8 @@ fn foo() { | |||
462 | check( | 485 | check( |
463 | r#"impl S { fn foo(&self) { <|> } }"#, | 486 | r#"impl S { fn foo(&self) { <|> } }"#, |
464 | expect![[r#" | 487 | expect![[r#" |
465 | tp Self | ||
466 | bn self &{unknown} | 488 | bn self &{unknown} |
489 | tp Self | ||
467 | "#]], | 490 | "#]], |
468 | ); | 491 | ); |
469 | } | 492 | } |
@@ -482,9 +505,9 @@ use prelude::*; | |||
482 | mod prelude { struct Option; } | 505 | mod prelude { struct Option; } |
483 | "#, | 506 | "#, |
484 | expect![[r#" | 507 | expect![[r#" |
485 | st Option | ||
486 | fn foo() fn foo() | 508 | fn foo() fn foo() |
487 | md std | 509 | md std |
510 | st Option | ||
488 | "#]], | 511 | "#]], |
489 | ); | 512 | ); |
490 | } | 513 | } |
@@ -509,10 +532,10 @@ use prelude::*; | |||
509 | mod prelude { struct String; } | 532 | mod prelude { struct String; } |
510 | "#, | 533 | "#, |
511 | expect![[r#" | 534 | expect![[r#" |
512 | st String | ||
513 | md core | ||
514 | fn foo() fn foo() | 535 | fn foo() fn foo() |
515 | md std | 536 | md std |
537 | md core | ||
538 | st String | ||
516 | "#]], | 539 | "#]], |
517 | ); | 540 | ); |
518 | } | 541 | } |
@@ -538,13 +561,13 @@ mod m2 { | |||
538 | fn main() { let v = <|> } | 561 | fn main() { let v = <|> } |
539 | "#, | 562 | "#, |
540 | expect![[r##" | 563 | expect![[r##" |
541 | ma bar!(…) macro_rules! bar | 564 | md m1 |
542 | ma baz!(…) #[macro_export] | 565 | ma baz!(…) #[macro_export] |
543 | macro_rules! baz | 566 | macro_rules! baz |
544 | ma foo!(…) macro_rules! foo | ||
545 | md m1 | ||
546 | md m2 | ||
547 | fn main() fn main() | 567 | fn main() fn main() |
568 | md m2 | ||
569 | ma bar!(…) macro_rules! bar | ||
570 | ma foo!(…) macro_rules! foo | ||
548 | "##]], | 571 | "##]], |
549 | ); | 572 | ); |
550 | } | 573 | } |
@@ -557,8 +580,8 @@ macro_rules! foo { () => {} } | |||
557 | fn foo() { <|> } | 580 | fn foo() { <|> } |
558 | "#, | 581 | "#, |
559 | expect![[r#" | 582 | expect![[r#" |
560 | ma foo!(…) macro_rules! foo | ||
561 | fn foo() fn foo() | 583 | fn foo() fn foo() |
584 | ma foo!(…) macro_rules! foo | ||
562 | "#]], | 585 | "#]], |
563 | ); | 586 | ); |
564 | } | 587 | } |
@@ -571,8 +594,8 @@ macro_rules! foo { () => {} } | |||
571 | fn main() { let x: <|> } | 594 | fn main() { let x: <|> } |
572 | "#, | 595 | "#, |
573 | expect![[r#" | 596 | expect![[r#" |
574 | ma foo!(…) macro_rules! foo | ||
575 | fn main() fn main() | 597 | fn main() fn main() |
598 | ma foo!(…) macro_rules! foo | ||
576 | "#]], | 599 | "#]], |
577 | ); | 600 | ); |
578 | } | 601 | } |
@@ -585,8 +608,8 @@ macro_rules! foo { () => {} } | |||
585 | fn main() { <|> } | 608 | fn main() { <|> } |
586 | "#, | 609 | "#, |
587 | expect![[r#" | 610 | expect![[r#" |
588 | ma foo!(…) macro_rules! foo | ||
589 | fn main() fn main() | 611 | fn main() fn main() |
612 | ma foo!(…) macro_rules! foo | ||
590 | "#]], | 613 | "#]], |
591 | ); | 614 | ); |
592 | } | 615 | } |
@@ -618,10 +641,10 @@ fn quux(x: i32) { | |||
618 | } | 641 | } |
619 | "#, | 642 | "#, |
620 | expect![[r#" | 643 | expect![[r#" |
621 | ma m!(…) macro_rules! m | ||
622 | fn quux(…) fn quux(x: i32) | ||
623 | bn x i32 | ||
624 | bn y i32 | 644 | bn y i32 |
645 | bn x i32 | ||
646 | fn quux(…) fn quux(x: i32) | ||
647 | ma m!(…) macro_rules! m | ||
625 | "#]], | 648 | "#]], |
626 | ); | 649 | ); |
627 | } | 650 | } |
@@ -637,10 +660,10 @@ fn quux(x: i32) { | |||
637 | } | 660 | } |
638 | ", | 661 | ", |
639 | expect![[r#" | 662 | expect![[r#" |
640 | ma m!(…) macro_rules! m | ||
641 | fn quux(…) fn quux(x: i32) | ||
642 | bn x i32 | ||
643 | bn y i32 | 663 | bn y i32 |
664 | bn x i32 | ||
665 | fn quux(…) fn quux(x: i32) | ||
666 | ma m!(…) macro_rules! m | ||
644 | "#]], | 667 | "#]], |
645 | ); | 668 | ); |
646 | } | 669 | } |
@@ -656,10 +679,10 @@ fn quux(x: i32) { | |||
656 | } | 679 | } |
657 | "#, | 680 | "#, |
658 | expect![[r#" | 681 | expect![[r#" |
659 | ma m!(…) macro_rules! m | ||
660 | fn quux(…) fn quux(x: i32) | ||
661 | bn x i32 | ||
662 | bn y i32 | 682 | bn y i32 |
683 | bn x i32 | ||
684 | fn quux(…) fn quux(x: i32) | ||
685 | ma m!(…) macro_rules! m | ||
663 | "#]], | 686 | "#]], |
664 | ); | 687 | ); |
665 | } | 688 | } |
@@ -673,8 +696,8 @@ use spam::Quux; | |||
673 | fn main() { <|> } | 696 | fn main() { <|> } |
674 | "#, | 697 | "#, |
675 | expect![[r#" | 698 | expect![[r#" |
676 | ?? Quux | ||
677 | fn main() fn main() | 699 | fn main() fn main() |
700 | ?? Quux | ||
678 | "#]], | 701 | "#]], |
679 | ); | 702 | ); |
680 | } | 703 | } |
@@ -690,10 +713,10 @@ fn main() { | |||
690 | } | 713 | } |
691 | "#, | 714 | "#, |
692 | expect![[r#" | 715 | expect![[r#" |
693 | en Foo | ||
694 | ev Foo::Bar () | 716 | ev Foo::Bar () |
695 | ev Foo::Baz () | 717 | ev Foo::Baz () |
696 | ev Foo::Quux () | 718 | ev Foo::Quux () |
719 | en Foo | ||
697 | "#]], | 720 | "#]], |
698 | ) | 721 | ) |
699 | } | 722 | } |
@@ -710,10 +733,10 @@ fn main() { | |||
710 | } | 733 | } |
711 | "#, | 734 | "#, |
712 | expect![[r#" | 735 | expect![[r#" |
713 | en Foo | ||
714 | ev Foo::Bar () | 736 | ev Foo::Bar () |
715 | ev Foo::Baz () | 737 | ev Foo::Baz () |
716 | ev Foo::Quux () | 738 | ev Foo::Quux () |
739 | en Foo | ||
717 | "#]], | 740 | "#]], |
718 | ) | 741 | ) |
719 | } | 742 | } |
@@ -726,10 +749,10 @@ enum Foo { Bar, Baz, Quux } | |||
726 | fn main() { let foo: Foo = Q<|> } | 749 | fn main() { let foo: Foo = Q<|> } |
727 | "#, | 750 | "#, |
728 | expect![[r#" | 751 | expect![[r#" |
729 | en Foo | ||
730 | ev Foo::Bar () | 752 | ev Foo::Bar () |
731 | ev Foo::Baz () | 753 | ev Foo::Baz () |
732 | ev Foo::Quux () | 754 | ev Foo::Quux () |
755 | en Foo | ||
733 | fn main() fn main() | 756 | fn main() fn main() |
734 | "#]], | 757 | "#]], |
735 | ) | 758 | ) |
@@ -743,9 +766,9 @@ mod m { pub enum E { V } } | |||
743 | fn f() -> m::E { V<|> } | 766 | fn f() -> m::E { V<|> } |
744 | "#, | 767 | "#, |
745 | expect![[r#" | 768 | expect![[r#" |
746 | fn f() fn f() -> m::E | ||
747 | md m | ||
748 | ev m::E::V () | 769 | ev m::E::V () |
770 | md m | ||
771 | fn f() fn f() -> m::E | ||
749 | "#]], | 772 | "#]], |
750 | ) | 773 | ) |
751 | } | 774 | } |
@@ -772,22 +795,17 @@ struct MyStruct {} | |||
772 | impl My<|> | 795 | impl My<|> |
773 | "#, | 796 | "#, |
774 | expect![[r#" | 797 | expect![[r#" |
775 | st MyStruct | ||
776 | tt MyTrait | ||
777 | tp Self | 798 | tp Self |
799 | tt MyTrait | ||
800 | st MyStruct | ||
778 | "#]], | 801 | "#]], |
779 | ) | 802 | ) |
780 | } | 803 | } |
781 | 804 | ||
782 | #[test] | 805 | #[test] |
783 | fn function_fuzzy_completion() { | 806 | fn function_fuzzy_completion() { |
784 | let mut completion_config = CompletionConfig::default(); | ||
785 | completion_config | ||
786 | .active_resolve_capabilities | ||
787 | .insert(crate::CompletionResolveCapability::AdditionalTextEdits); | ||
788 | |||
789 | check_edit_with_config( | 807 | check_edit_with_config( |
790 | completion_config, | 808 | fuzzy_completion_config(), |
791 | "stdin", | 809 | "stdin", |
792 | r#" | 810 | r#" |
793 | //- /lib.rs crate:dep | 811 | //- /lib.rs crate:dep |
@@ -812,13 +830,8 @@ fn main() { | |||
812 | 830 | ||
813 | #[test] | 831 | #[test] |
814 | fn macro_fuzzy_completion() { | 832 | fn macro_fuzzy_completion() { |
815 | let mut completion_config = CompletionConfig::default(); | ||
816 | completion_config | ||
817 | .active_resolve_capabilities | ||
818 | .insert(crate::CompletionResolveCapability::AdditionalTextEdits); | ||
819 | |||
820 | check_edit_with_config( | 833 | check_edit_with_config( |
821 | completion_config, | 834 | fuzzy_completion_config(), |
822 | "macro_with_curlies!", | 835 | "macro_with_curlies!", |
823 | r#" | 836 | r#" |
824 | //- /lib.rs crate:dep | 837 | //- /lib.rs crate:dep |
@@ -845,13 +858,8 @@ fn main() { | |||
845 | 858 | ||
846 | #[test] | 859 | #[test] |
847 | fn struct_fuzzy_completion() { | 860 | fn struct_fuzzy_completion() { |
848 | let mut completion_config = CompletionConfig::default(); | ||
849 | completion_config | ||
850 | .active_resolve_capabilities | ||
851 | .insert(crate::CompletionResolveCapability::AdditionalTextEdits); | ||
852 | |||
853 | check_edit_with_config( | 861 | check_edit_with_config( |
854 | completion_config, | 862 | fuzzy_completion_config(), |
855 | "ThirdStruct", | 863 | "ThirdStruct", |
856 | r#" | 864 | r#" |
857 | //- /lib.rs crate:dep | 865 | //- /lib.rs crate:dep |
@@ -877,4 +885,44 @@ fn main() { | |||
877 | "#, | 885 | "#, |
878 | ); | 886 | ); |
879 | } | 887 | } |
888 | |||
889 | #[test] | ||
890 | fn fuzzy_completions_come_in_specific_order() { | ||
891 | mark::check!(certain_fuzzy_order_test); | ||
892 | check_with_config( | ||
893 | fuzzy_completion_config(), | ||
894 | r#" | ||
895 | //- /lib.rs crate:dep | ||
896 | pub struct FirstStruct; | ||
897 | pub mod some_module { | ||
898 | // already imported, omitted | ||
899 | pub struct SecondStruct; | ||
900 | // does not contain all letters from the query, omitted | ||
901 | pub struct UnrelatedOne; | ||
902 | // contains all letters from the query, but not in sequence, displayed last | ||
903 | pub struct ThiiiiiirdStruct; | ||
904 | // contains all letters from the query, but not in the beginning, displayed second | ||
905 | pub struct AfterThirdStruct; | ||
906 | // contains all letters from the query in the begginning, displayed first | ||
907 | pub struct ThirdStruct; | ||
908 | } | ||
909 | |||
910 | //- /main.rs crate:main deps:dep | ||
911 | use dep::{FirstStruct, some_module::SecondStruct}; | ||
912 | |||
913 | fn main() { | ||
914 | hir<|> | ||
915 | } | ||
916 | "#, | ||
917 | expect![[r#" | ||
918 | fn main() fn main() | ||
919 | st SecondStruct | ||
920 | st FirstStruct | ||
921 | md dep | ||
922 | st dep::some_module::ThirdStruct | ||
923 | st dep::some_module::AfterThirdStruct | ||
924 | st dep::some_module::ThiiiiiirdStruct | ||
925 | "#]], | ||
926 | ); | ||
927 | } | ||
880 | } | 928 | } |
diff --git a/crates/completion/src/test_utils.rs b/crates/completion/src/test_utils.rs index db896b2df..eb0c16f52 100644 --- a/crates/completion/src/test_utils.rs +++ b/crates/completion/src/test_utils.rs | |||
@@ -47,9 +47,8 @@ pub(crate) fn completion_list_with_config( | |||
47 | code: &str, | 47 | code: &str, |
48 | kind: CompletionKind, | 48 | kind: CompletionKind, |
49 | ) -> String { | 49 | ) -> String { |
50 | let mut kind_completions: Vec<CompletionItem> = | 50 | let kind_completions: Vec<CompletionItem> = |
51 | get_all_items(config, code).into_iter().filter(|c| c.completion_kind == kind).collect(); | 51 | get_all_items(config, code).into_iter().filter(|c| c.completion_kind == kind).collect(); |
52 | kind_completions.sort_by_key(|c| c.label().to_owned()); | ||
53 | let label_width = kind_completions | 52 | let label_width = kind_completions |
54 | .iter() | 53 | .iter() |
55 | .map(|it| monospace_width(it.label())) | 54 | .map(|it| monospace_width(it.label())) |