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 | 192 |
1 files changed, 192 insertions, 0 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index 67fb7ba4e..2062e7300 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs | |||
@@ -532,4 +532,196 @@ mod tests { | |||
532 | ]"# | 532 | ]"# |
533 | ); | 533 | ); |
534 | } | 534 | } |
535 | |||
536 | #[test] | ||
537 | fn completes_macros_as_value() { | ||
538 | assert_debug_snapshot!( | ||
539 | do_reference_completion( | ||
540 | " | ||
541 | //- /main.rs | ||
542 | macro_rules! foo { | ||
543 | () => {} | ||
544 | } | ||
545 | |||
546 | #[macro_use] | ||
547 | mod m1 { | ||
548 | macro_rules! bar { | ||
549 | () => {} | ||
550 | } | ||
551 | } | ||
552 | |||
553 | mod m2 { | ||
554 | macro_rules! nope { | ||
555 | () => {} | ||
556 | } | ||
557 | |||
558 | #[macro_export] | ||
559 | macro_rules! baz { | ||
560 | () => {} | ||
561 | } | ||
562 | } | ||
563 | |||
564 | fn main() { | ||
565 | let v = <|> | ||
566 | } | ||
567 | " | ||
568 | ), | ||
569 | @r##"[ | ||
570 | CompletionItem { | ||
571 | label: "bar", | ||
572 | source_range: [252; 252), | ||
573 | delete: [252; 252), | ||
574 | insert: "bar!", | ||
575 | kind: Macro, | ||
576 | detail: "macro_rules! bar", | ||
577 | }, | ||
578 | CompletionItem { | ||
579 | label: "baz", | ||
580 | source_range: [252; 252), | ||
581 | delete: [252; 252), | ||
582 | insert: "baz!", | ||
583 | kind: Macro, | ||
584 | detail: "#[macro_export]\nmacro_rules! baz", | ||
585 | }, | ||
586 | CompletionItem { | ||
587 | label: "foo", | ||
588 | source_range: [252; 252), | ||
589 | delete: [252; 252), | ||
590 | insert: "foo!", | ||
591 | kind: Macro, | ||
592 | detail: "macro_rules! foo", | ||
593 | }, | ||
594 | CompletionItem { | ||
595 | label: "m1", | ||
596 | source_range: [252; 252), | ||
597 | delete: [252; 252), | ||
598 | insert: "m1", | ||
599 | kind: Module, | ||
600 | }, | ||
601 | CompletionItem { | ||
602 | label: "m2", | ||
603 | source_range: [252; 252), | ||
604 | delete: [252; 252), | ||
605 | insert: "m2", | ||
606 | kind: Module, | ||
607 | }, | ||
608 | CompletionItem { | ||
609 | label: "main", | ||
610 | source_range: [252; 252), | ||
611 | delete: [252; 252), | ||
612 | insert: "main()$0", | ||
613 | kind: Function, | ||
614 | detail: "fn main()", | ||
615 | }, | ||
616 | ]"## | ||
617 | ); | ||
618 | } | ||
619 | |||
620 | #[test] | ||
621 | fn completes_both_macro_and_value() { | ||
622 | assert_debug_snapshot!( | ||
623 | do_reference_completion( | ||
624 | " | ||
625 | //- /main.rs | ||
626 | macro_rules! foo { | ||
627 | () => {} | ||
628 | } | ||
629 | |||
630 | fn foo() { | ||
631 | <|> | ||
632 | } | ||
633 | " | ||
634 | ), | ||
635 | @r##"[ | ||
636 | CompletionItem { | ||
637 | label: "foo", | ||
638 | source_range: [49; 49), | ||
639 | delete: [49; 49), | ||
640 | insert: "foo!", | ||
641 | kind: Macro, | ||
642 | detail: "macro_rules! foo", | ||
643 | }, | ||
644 | CompletionItem { | ||
645 | label: "foo", | ||
646 | source_range: [49; 49), | ||
647 | delete: [49; 49), | ||
648 | insert: "foo()$0", | ||
649 | kind: Function, | ||
650 | detail: "fn foo()", | ||
651 | }, | ||
652 | ]"## | ||
653 | ); | ||
654 | } | ||
655 | |||
656 | #[test] | ||
657 | fn completes_macros_as_type() { | ||
658 | assert_debug_snapshot!( | ||
659 | do_reference_completion( | ||
660 | " | ||
661 | //- /main.rs | ||
662 | macro_rules! foo { | ||
663 | () => {} | ||
664 | } | ||
665 | |||
666 | fn main() { | ||
667 | let x: <|> | ||
668 | } | ||
669 | " | ||
670 | ), | ||
671 | @r##"[ | ||
672 | CompletionItem { | ||
673 | label: "foo", | ||
674 | source_range: [57; 57), | ||
675 | delete: [57; 57), | ||
676 | insert: "foo!", | ||
677 | kind: Macro, | ||
678 | detail: "macro_rules! foo", | ||
679 | }, | ||
680 | CompletionItem { | ||
681 | label: "main", | ||
682 | source_range: [57; 57), | ||
683 | delete: [57; 57), | ||
684 | insert: "main()$0", | ||
685 | kind: Function, | ||
686 | detail: "fn main()", | ||
687 | }, | ||
688 | ]"## | ||
689 | ); | ||
690 | } | ||
691 | |||
692 | #[test] | ||
693 | fn completes_macros_as_stmt() { | ||
694 | assert_debug_snapshot!( | ||
695 | do_reference_completion( | ||
696 | " | ||
697 | //- /main.rs | ||
698 | macro_rules! foo { | ||
699 | () => {} | ||
700 | } | ||
701 | |||
702 | fn main() { | ||
703 | <|> | ||
704 | } | ||
705 | " | ||
706 | ), | ||
707 | @r##"[ | ||
708 | CompletionItem { | ||
709 | label: "foo", | ||
710 | source_range: [50; 50), | ||
711 | delete: [50; 50), | ||
712 | insert: "foo!", | ||
713 | kind: Macro, | ||
714 | detail: "macro_rules! foo", | ||
715 | }, | ||
716 | CompletionItem { | ||
717 | label: "main", | ||
718 | source_range: [50; 50), | ||
719 | delete: [50; 50), | ||
720 | insert: "main()$0", | ||
721 | kind: Function, | ||
722 | detail: "fn main()", | ||
723 | }, | ||
724 | ]"## | ||
725 | ); | ||
726 | } | ||
535 | } | 727 | } |