diff options
Diffstat (limited to 'crates/ra_ide_api/src/completion/complete_scope.rs')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_scope.rs | 534 |
1 files changed, 285 insertions, 249 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index 84826cdcc..b64540365 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs | |||
@@ -145,32 +145,35 @@ mod tests { | |||
145 | } | 145 | } |
146 | " | 146 | " |
147 | ), | 147 | ), |
148 | @r###"[ | 148 | @r###" |
149 | CompletionItem { | 149 | [ |
150 | label: "quux", | 150 | CompletionItem { |
151 | source_range: [91; 91), | 151 | label: "quux(…)", |
152 | delete: [91; 91), | 152 | source_range: [91; 91), |
153 | insert: "quux($0)", | 153 | delete: [91; 91), |
154 | kind: Function, | 154 | insert: "quux($0)", |
155 | detail: "fn quux(x: i32)", | 155 | kind: Function, |
156 | }, | 156 | lookup: "quux", |
157 | CompletionItem { | 157 | detail: "fn quux(x: i32)", |
158 | label: "x", | 158 | }, |
159 | source_range: [91; 91), | 159 | CompletionItem { |
160 | delete: [91; 91), | 160 | label: "x", |
161 | insert: "x", | 161 | source_range: [91; 91), |
162 | kind: Binding, | 162 | delete: [91; 91), |
163 | detail: "i32", | 163 | insert: "x", |
164 | }, | 164 | kind: Binding, |
165 | CompletionItem { | 165 | detail: "i32", |
166 | label: "y", | 166 | }, |
167 | source_range: [91; 91), | 167 | CompletionItem { |
168 | delete: [91; 91), | 168 | label: "y", |
169 | insert: "y", | 169 | source_range: [91; 91), |
170 | kind: Binding, | 170 | delete: [91; 91), |
171 | detail: "i32", | 171 | insert: "y", |
172 | }, | 172 | kind: Binding, |
173 | ]"### | 173 | detail: "i32", |
174 | }, | ||
175 | ] | ||
176 | "### | ||
174 | ); | 177 | ); |
175 | } | 178 | } |
176 | 179 | ||
@@ -190,31 +193,34 @@ mod tests { | |||
190 | } | 193 | } |
191 | " | 194 | " |
192 | ), | 195 | ), |
193 | @r###"[ | 196 | @r###" |
194 | CompletionItem { | 197 | [ |
195 | label: "a", | 198 | CompletionItem { |
196 | source_range: [242; 242), | 199 | label: "a", |
197 | delete: [242; 242), | 200 | source_range: [242; 242), |
198 | insert: "a", | 201 | delete: [242; 242), |
199 | kind: Binding, | 202 | insert: "a", |
200 | }, | 203 | kind: Binding, |
201 | CompletionItem { | 204 | }, |
202 | label: "b", | 205 | CompletionItem { |
203 | source_range: [242; 242), | 206 | label: "b", |
204 | delete: [242; 242), | 207 | source_range: [242; 242), |
205 | insert: "b", | 208 | delete: [242; 242), |
206 | kind: Binding, | 209 | insert: "b", |
207 | detail: "i32", | 210 | kind: Binding, |
208 | }, | 211 | detail: "i32", |
209 | CompletionItem { | 212 | }, |
210 | label: "quux", | 213 | CompletionItem { |
211 | source_range: [242; 242), | 214 | label: "quux(…)", |
212 | delete: [242; 242), | 215 | source_range: [242; 242), |
213 | insert: "quux()$0", | 216 | delete: [242; 242), |
214 | kind: Function, | 217 | insert: "quux()$0", |
215 | detail: "fn quux()", | 218 | kind: Function, |
216 | }, | 219 | lookup: "quux", |
217 | ]"### | 220 | detail: "fn quux()", |
221 | }, | ||
222 | ] | ||
223 | "### | ||
218 | ); | 224 | ); |
219 | } | 225 | } |
220 | 226 | ||
@@ -230,23 +236,26 @@ mod tests { | |||
230 | } | 236 | } |
231 | " | 237 | " |
232 | ), | 238 | ), |
233 | @r###"[ | 239 | @r###" |
234 | CompletionItem { | 240 | [ |
235 | label: "quux", | 241 | CompletionItem { |
236 | source_range: [95; 95), | 242 | label: "quux(…)", |
237 | delete: [95; 95), | 243 | source_range: [95; 95), |
238 | insert: "quux()$0", | 244 | delete: [95; 95), |
239 | kind: Function, | 245 | insert: "quux()$0", |
240 | detail: "fn quux()", | 246 | kind: Function, |
241 | }, | 247 | lookup: "quux", |
242 | CompletionItem { | 248 | detail: "fn quux()", |
243 | label: "x", | 249 | }, |
244 | source_range: [95; 95), | 250 | CompletionItem { |
245 | delete: [95; 95), | 251 | label: "x", |
246 | insert: "x", | 252 | source_range: [95; 95), |
247 | kind: Binding, | 253 | delete: [95; 95), |
248 | }, | 254 | insert: "x", |
249 | ]"### | 255 | kind: Binding, |
256 | }, | ||
257 | ] | ||
258 | "### | ||
250 | ); | 259 | ); |
251 | } | 260 | } |
252 | 261 | ||
@@ -260,23 +269,26 @@ mod tests { | |||
260 | } | 269 | } |
261 | " | 270 | " |
262 | ), | 271 | ), |
263 | @r###"[ | 272 | @r###" |
264 | CompletionItem { | 273 | [ |
265 | label: "T", | 274 | CompletionItem { |
266 | source_range: [52; 52), | 275 | label: "T", |
267 | delete: [52; 52), | 276 | source_range: [52; 52), |
268 | insert: "T", | 277 | delete: [52; 52), |
269 | kind: TypeParam, | 278 | insert: "T", |
270 | }, | 279 | kind: TypeParam, |
271 | CompletionItem { | 280 | }, |
272 | label: "quux", | 281 | CompletionItem { |
273 | source_range: [52; 52), | 282 | label: "quux(…)", |
274 | delete: [52; 52), | 283 | source_range: [52; 52), |
275 | insert: "quux()$0", | 284 | delete: [52; 52), |
276 | kind: Function, | 285 | insert: "quux()$0", |
277 | detail: "fn quux<T>()", | 286 | kind: Function, |
278 | }, | 287 | lookup: "quux", |
279 | ]"### | 288 | detail: "fn quux<T>()", |
289 | }, | ||
290 | ] | ||
291 | "### | ||
280 | ); | 292 | ); |
281 | } | 293 | } |
282 | 294 | ||
@@ -300,11 +312,12 @@ mod tests { | |||
300 | kind: TypeParam, | 312 | kind: TypeParam, |
301 | }, | 313 | }, |
302 | CompletionItem { | 314 | CompletionItem { |
303 | label: "X", | 315 | label: "X<…>", |
304 | source_range: [54; 54), | 316 | source_range: [54; 54), |
305 | delete: [54; 54), | 317 | delete: [54; 54), |
306 | insert: "X<$0>", | 318 | insert: "X<$0>", |
307 | kind: Struct, | 319 | kind: Struct, |
320 | lookup: "X", | ||
308 | }, | 321 | }, |
309 | ] | 322 | ] |
310 | "### | 323 | "### |
@@ -354,30 +367,33 @@ mod tests { | |||
354 | } | 367 | } |
355 | " | 368 | " |
356 | ), | 369 | ), |
357 | @r###"[ | 370 | @r###" |
358 | CompletionItem { | 371 | [ |
359 | label: "Baz", | 372 | CompletionItem { |
360 | source_range: [105; 105), | 373 | label: "Baz", |
361 | delete: [105; 105), | 374 | source_range: [105; 105), |
362 | insert: "Baz", | 375 | delete: [105; 105), |
363 | kind: Enum, | 376 | insert: "Baz", |
364 | }, | 377 | kind: Enum, |
365 | CompletionItem { | 378 | }, |
366 | label: "Foo", | 379 | CompletionItem { |
367 | source_range: [105; 105), | 380 | label: "Foo", |
368 | delete: [105; 105), | 381 | source_range: [105; 105), |
369 | insert: "Foo", | 382 | delete: [105; 105), |
370 | kind: Struct, | 383 | insert: "Foo", |
371 | }, | 384 | kind: Struct, |
372 | CompletionItem { | 385 | }, |
373 | label: "quux", | 386 | CompletionItem { |
374 | source_range: [105; 105), | 387 | label: "quux(…)", |
375 | delete: [105; 105), | 388 | source_range: [105; 105), |
376 | insert: "quux()$0", | 389 | delete: [105; 105), |
377 | kind: Function, | 390 | insert: "quux()$0", |
378 | detail: "fn quux()", | 391 | kind: Function, |
379 | }, | 392 | lookup: "quux", |
380 | ]"### | 393 | detail: "fn quux()", |
394 | }, | ||
395 | ] | ||
396 | "### | ||
381 | ); | 397 | ); |
382 | } | 398 | } |
383 | 399 | ||
@@ -417,23 +433,26 @@ mod tests { | |||
417 | } | 433 | } |
418 | " | 434 | " |
419 | ), | 435 | ), |
420 | @r###"[ | 436 | @r###" |
421 | CompletionItem { | 437 | [ |
422 | label: "Bar", | 438 | CompletionItem { |
423 | source_range: [117; 117), | 439 | label: "Bar", |
424 | delete: [117; 117), | 440 | source_range: [117; 117), |
425 | insert: "Bar", | 441 | delete: [117; 117), |
426 | kind: Struct, | 442 | insert: "Bar", |
427 | }, | 443 | kind: Struct, |
428 | CompletionItem { | 444 | }, |
429 | label: "quux", | 445 | CompletionItem { |
430 | source_range: [117; 117), | 446 | label: "quux(…)", |
431 | delete: [117; 117), | 447 | source_range: [117; 117), |
432 | insert: "quux()$0", | 448 | delete: [117; 117), |
433 | kind: Function, | 449 | insert: "quux()$0", |
434 | detail: "fn quux()", | 450 | kind: Function, |
435 | }, | 451 | lookup: "quux", |
436 | ]"### | 452 | detail: "fn quux()", |
453 | }, | ||
454 | ] | ||
455 | "### | ||
437 | ); | 456 | ); |
438 | } | 457 | } |
439 | 458 | ||
@@ -456,11 +475,12 @@ mod tests { | |||
456 | kind: Struct, | 475 | kind: Struct, |
457 | }, | 476 | }, |
458 | CompletionItem { | 477 | CompletionItem { |
459 | label: "x", | 478 | label: "x(…)", |
460 | source_range: [55; 55), | 479 | source_range: [55; 55), |
461 | delete: [55; 55), | 480 | delete: [55; 55), |
462 | insert: "x()$0", | 481 | insert: "x()$0", |
463 | kind: Function, | 482 | kind: Function, |
483 | lookup: "x", | ||
464 | detail: "fn x()", | 484 | detail: "fn x()", |
465 | }, | 485 | }, |
466 | ] | 486 | ] |
@@ -482,24 +502,27 @@ mod tests { | |||
482 | } | 502 | } |
483 | " | 503 | " |
484 | ), | 504 | ), |
485 | @r###"[ | 505 | @r###" |
486 | CompletionItem { | 506 | [ |
487 | label: "bar", | 507 | CompletionItem { |
488 | source_range: [146; 146), | 508 | label: "bar", |
489 | delete: [146; 146), | 509 | source_range: [146; 146), |
490 | insert: "bar", | 510 | delete: [146; 146), |
491 | kind: Binding, | 511 | insert: "bar", |
492 | detail: "i32", | 512 | kind: Binding, |
493 | }, | 513 | detail: "i32", |
494 | CompletionItem { | 514 | }, |
495 | label: "foo", | 515 | CompletionItem { |
496 | source_range: [146; 146), | 516 | label: "foo(…)", |
497 | delete: [146; 146), | 517 | source_range: [146; 146), |
498 | insert: "foo()$0", | 518 | delete: [146; 146), |
499 | kind: Function, | 519 | insert: "foo()$0", |
500 | detail: "fn foo()", | 520 | kind: Function, |
501 | }, | 521 | lookup: "foo", |
502 | ]"### | 522 | detail: "fn foo()", |
523 | }, | ||
524 | ] | ||
525 | "### | ||
503 | ); | 526 | ); |
504 | } | 527 | } |
505 | 528 | ||
@@ -554,11 +577,12 @@ mod tests { | |||
554 | kind: Struct, | 577 | kind: Struct, |
555 | }, | 578 | }, |
556 | CompletionItem { | 579 | CompletionItem { |
557 | label: "foo", | 580 | label: "foo(…)", |
558 | source_range: [18; 18), | 581 | source_range: [18; 18), |
559 | delete: [18; 18), | 582 | delete: [18; 18), |
560 | insert: "foo()$0", | 583 | insert: "foo()$0", |
561 | kind: Function, | 584 | kind: Function, |
585 | lookup: "foo", | ||
562 | detail: "fn foo()", | 586 | detail: "fn foo()", |
563 | }, | 587 | }, |
564 | CompletionItem { | 588 | CompletionItem { |
@@ -606,54 +630,57 @@ mod tests { | |||
606 | } | 630 | } |
607 | " | 631 | " |
608 | ), | 632 | ), |
609 | @r##"[ | 633 | @r###" |
610 | CompletionItem { | 634 | [ |
611 | label: "bar!", | 635 | CompletionItem { |
612 | source_range: [252; 252), | 636 | label: "bar!", |
613 | delete: [252; 252), | 637 | source_range: [252; 252), |
614 | insert: "bar!($0)", | 638 | delete: [252; 252), |
615 | kind: Macro, | 639 | insert: "bar!($0)", |
616 | detail: "macro_rules! bar", | 640 | kind: Macro, |
617 | }, | 641 | detail: "macro_rules! bar", |
618 | CompletionItem { | 642 | }, |
619 | label: "baz!", | 643 | CompletionItem { |
620 | source_range: [252; 252), | 644 | label: "baz!", |
621 | delete: [252; 252), | 645 | source_range: [252; 252), |
622 | insert: "baz!($0)", | 646 | delete: [252; 252), |
623 | kind: Macro, | 647 | insert: "baz!($0)", |
624 | detail: "#[macro_export]\nmacro_rules! baz", | 648 | kind: Macro, |
625 | }, | 649 | detail: "#[macro_export]\nmacro_rules! baz", |
626 | CompletionItem { | 650 | }, |
627 | label: "foo!", | 651 | CompletionItem { |
628 | source_range: [252; 252), | 652 | label: "foo!", |
629 | delete: [252; 252), | 653 | source_range: [252; 252), |
630 | insert: "foo!($0)", | 654 | delete: [252; 252), |
631 | kind: Macro, | 655 | insert: "foo!($0)", |
632 | detail: "macro_rules! foo", | 656 | kind: Macro, |
633 | }, | 657 | detail: "macro_rules! foo", |
634 | CompletionItem { | 658 | }, |
635 | label: "m1", | 659 | CompletionItem { |
636 | source_range: [252; 252), | 660 | label: "m1", |
637 | delete: [252; 252), | 661 | source_range: [252; 252), |
638 | insert: "m1", | 662 | delete: [252; 252), |
639 | kind: Module, | 663 | insert: "m1", |
640 | }, | 664 | kind: Module, |
641 | CompletionItem { | 665 | }, |
642 | label: "m2", | 666 | CompletionItem { |
643 | source_range: [252; 252), | 667 | label: "m2", |
644 | delete: [252; 252), | 668 | source_range: [252; 252), |
645 | insert: "m2", | 669 | delete: [252; 252), |
646 | kind: Module, | 670 | insert: "m2", |
647 | }, | 671 | kind: Module, |
648 | CompletionItem { | 672 | }, |
649 | label: "main", | 673 | CompletionItem { |
650 | source_range: [252; 252), | 674 | label: "main(…)", |
651 | delete: [252; 252), | 675 | source_range: [252; 252), |
652 | insert: "main()$0", | 676 | delete: [252; 252), |
653 | kind: Function, | 677 | insert: "main()$0", |
654 | detail: "fn main()", | 678 | kind: Function, |
655 | }, | 679 | lookup: "main", |
656 | ]"## | 680 | detail: "fn main()", |
681 | }, | ||
682 | ] | ||
683 | "### | ||
657 | ); | 684 | ); |
658 | } | 685 | } |
659 | 686 | ||
@@ -672,24 +699,27 @@ mod tests { | |||
672 | } | 699 | } |
673 | " | 700 | " |
674 | ), | 701 | ), |
675 | @r##"[ | 702 | @r###" |
676 | CompletionItem { | 703 | [ |
677 | label: "foo", | 704 | CompletionItem { |
678 | source_range: [49; 49), | 705 | label: "foo!", |
679 | delete: [49; 49), | 706 | source_range: [49; 49), |
680 | insert: "foo()$0", | 707 | delete: [49; 49), |
681 | kind: Function, | 708 | insert: "foo!($0)", |
682 | detail: "fn foo()", | 709 | kind: Macro, |
683 | }, | 710 | detail: "macro_rules! foo", |
684 | CompletionItem { | 711 | }, |
685 | label: "foo!", | 712 | CompletionItem { |
686 | source_range: [49; 49), | 713 | label: "foo(…)", |
687 | delete: [49; 49), | 714 | source_range: [49; 49), |
688 | insert: "foo!($0)", | 715 | delete: [49; 49), |
689 | kind: Macro, | 716 | insert: "foo()$0", |
690 | detail: "macro_rules! foo", | 717 | kind: Function, |
691 | }, | 718 | lookup: "foo", |
692 | ]"## | 719 | detail: "fn foo()", |
720 | }, | ||
721 | ] | ||
722 | "### | ||
693 | ); | 723 | ); |
694 | } | 724 | } |
695 | 725 | ||
@@ -708,24 +738,27 @@ mod tests { | |||
708 | } | 738 | } |
709 | " | 739 | " |
710 | ), | 740 | ), |
711 | @r##"[ | 741 | @r###" |
712 | CompletionItem { | 742 | [ |
713 | label: "foo!", | 743 | CompletionItem { |
714 | source_range: [57; 57), | 744 | label: "foo!", |
715 | delete: [57; 57), | 745 | source_range: [57; 57), |
716 | insert: "foo!($0)", | 746 | delete: [57; 57), |
717 | kind: Macro, | 747 | insert: "foo!($0)", |
718 | detail: "macro_rules! foo", | 748 | kind: Macro, |
719 | }, | 749 | detail: "macro_rules! foo", |
720 | CompletionItem { | 750 | }, |
721 | label: "main", | 751 | CompletionItem { |
722 | source_range: [57; 57), | 752 | label: "main(…)", |
723 | delete: [57; 57), | 753 | source_range: [57; 57), |
724 | insert: "main()$0", | 754 | delete: [57; 57), |
725 | kind: Function, | 755 | insert: "main()$0", |
726 | detail: "fn main()", | 756 | kind: Function, |
727 | }, | 757 | lookup: "main", |
728 | ]"## | 758 | detail: "fn main()", |
759 | }, | ||
760 | ] | ||
761 | "### | ||
729 | ); | 762 | ); |
730 | } | 763 | } |
731 | 764 | ||
@@ -744,24 +777,27 @@ mod tests { | |||
744 | } | 777 | } |
745 | " | 778 | " |
746 | ), | 779 | ), |
747 | @r##"[ | 780 | @r###" |
748 | CompletionItem { | 781 | [ |
749 | label: "foo!", | 782 | CompletionItem { |
750 | source_range: [50; 50), | 783 | label: "foo!", |
751 | delete: [50; 50), | 784 | source_range: [50; 50), |
752 | insert: "foo!($0)", | 785 | delete: [50; 50), |
753 | kind: Macro, | 786 | insert: "foo!($0)", |
754 | detail: "macro_rules! foo", | 787 | kind: Macro, |
755 | }, | 788 | detail: "macro_rules! foo", |
756 | CompletionItem { | 789 | }, |
757 | label: "main", | 790 | CompletionItem { |
758 | source_range: [50; 50), | 791 | label: "main(…)", |
759 | delete: [50; 50), | 792 | source_range: [50; 50), |
760 | insert: "main()$0", | 793 | delete: [50; 50), |
761 | kind: Function, | 794 | insert: "main()$0", |
762 | detail: "fn main()", | 795 | kind: Function, |
763 | }, | 796 | lookup: "main", |
764 | ]"## | 797 | detail: "fn main()", |
798 | }, | ||
799 | ] | ||
800 | "### | ||
765 | ); | 801 | ); |
766 | } | 802 | } |
767 | } | 803 | } |