aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r--crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs32
-rw-r--r--crates/ra_ide_api/src/completion/complete_path.rs4
-rw-r--r--crates/ra_ide_api/src/completion/complete_scope.rs34
-rw-r--r--crates/ra_ide_api/src/completion/presentation.rs21
4 files changed, 64 insertions, 27 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs b/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs
index 708dc9777..6fcef4a72 100644
--- a/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs
+++ b/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs
@@ -37,14 +37,42 @@ mod tests {
37 ), 37 ),
38 @r##"[ 38 @r##"[
39 CompletionItem { 39 CompletionItem {
40 label: "foo", 40 label: "foo!",
41 source_range: [46; 46), 41 source_range: [46; 46),
42 delete: [46; 46), 42 delete: [46; 46),
43 insert: "foo!", 43 insert: "foo!($0)",
44 kind: Macro, 44 kind: Macro,
45 detail: "macro_rules! foo", 45 detail: "macro_rules! foo",
46 }, 46 },
47]"## 47]"##
48 ); 48 );
49 } 49 }
50
51 #[test]
52 fn completes_vec_macros_with_square_brackets() {
53 assert_debug_snapshot!(
54 do_reference_completion(
55 "
56 //- /main.rs
57 macro_rules! vec {
58 () => {}
59 }
60
61 fn foo() {}
62
63 <|>
64 "
65 ),
66 @r##"[
67 CompletionItem {
68 label: "vec!",
69 source_range: [46; 46),
70 delete: [46; 46),
71 insert: "vec![$0]",
72 kind: Macro,
73 detail: "macro_rules! vec",
74 },
75]"##
76 );
77 }
50} 78}
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs
index 31e7dffe8..457a3d10c 100644
--- a/crates/ra_ide_api/src/completion/complete_path.rs
+++ b/crates/ra_ide_api/src/completion/complete_path.rs
@@ -605,10 +605,10 @@ mod tests {
605 ), 605 ),
606 @r###"[ 606 @r###"[
607 CompletionItem { 607 CompletionItem {
608 label: "foo", 608 label: "foo!",
609 source_range: [179; 179), 609 source_range: [179; 179),
610 delete: [179; 179), 610 delete: [179; 179),
611 insert: "foo!", 611 insert: "foo!($0)",
612 kind: Macro, 612 kind: Macro,
613 detail: "#[macro_export]\nmacro_rules! foo", 613 detail: "#[macro_export]\nmacro_rules! foo",
614 }, 614 },
diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs
index 2062e7300..2ea22876f 100644
--- a/crates/ra_ide_api/src/completion/complete_scope.rs
+++ b/crates/ra_ide_api/src/completion/complete_scope.rs
@@ -568,26 +568,26 @@ mod tests {
568 ), 568 ),
569 @r##"[ 569 @r##"[
570 CompletionItem { 570 CompletionItem {
571 label: "bar", 571 label: "bar!",
572 source_range: [252; 252), 572 source_range: [252; 252),
573 delete: [252; 252), 573 delete: [252; 252),
574 insert: "bar!", 574 insert: "bar!($0)",
575 kind: Macro, 575 kind: Macro,
576 detail: "macro_rules! bar", 576 detail: "macro_rules! bar",
577 }, 577 },
578 CompletionItem { 578 CompletionItem {
579 label: "baz", 579 label: "baz!",
580 source_range: [252; 252), 580 source_range: [252; 252),
581 delete: [252; 252), 581 delete: [252; 252),
582 insert: "baz!", 582 insert: "baz!($0)",
583 kind: Macro, 583 kind: Macro,
584 detail: "#[macro_export]\nmacro_rules! baz", 584 detail: "#[macro_export]\nmacro_rules! baz",
585 }, 585 },
586 CompletionItem { 586 CompletionItem {
587 label: "foo", 587 label: "foo!",
588 source_range: [252; 252), 588 source_range: [252; 252),
589 delete: [252; 252), 589 delete: [252; 252),
590 insert: "foo!", 590 insert: "foo!($0)",
591 kind: Macro, 591 kind: Macro,
592 detail: "macro_rules! foo", 592 detail: "macro_rules! foo",
593 }, 593 },
@@ -637,17 +637,17 @@ mod tests {
637 label: "foo", 637 label: "foo",
638 source_range: [49; 49), 638 source_range: [49; 49),
639 delete: [49; 49), 639 delete: [49; 49),
640 insert: "foo!", 640 insert: "foo()$0",
641 kind: Macro, 641 kind: Function,
642 detail: "macro_rules! foo", 642 detail: "fn foo()",
643 }, 643 },
644 CompletionItem { 644 CompletionItem {
645 label: "foo", 645 label: "foo!",
646 source_range: [49; 49), 646 source_range: [49; 49),
647 delete: [49; 49), 647 delete: [49; 49),
648 insert: "foo()$0", 648 insert: "foo!($0)",
649 kind: Function, 649 kind: Macro,
650 detail: "fn foo()", 650 detail: "macro_rules! foo",
651 }, 651 },
652]"## 652]"##
653 ); 653 );
@@ -670,10 +670,10 @@ mod tests {
670 ), 670 ),
671 @r##"[ 671 @r##"[
672 CompletionItem { 672 CompletionItem {
673 label: "foo", 673 label: "foo!",
674 source_range: [57; 57), 674 source_range: [57; 57),
675 delete: [57; 57), 675 delete: [57; 57),
676 insert: "foo!", 676 insert: "foo!($0)",
677 kind: Macro, 677 kind: Macro,
678 detail: "macro_rules! foo", 678 detail: "macro_rules! foo",
679 }, 679 },
@@ -706,10 +706,10 @@ mod tests {
706 ), 706 ),
707 @r##"[ 707 @r##"[
708 CompletionItem { 708 CompletionItem {
709 label: "foo", 709 label: "foo!",
710 source_range: [50; 50), 710 source_range: [50; 50),
711 delete: [50; 50), 711 delete: [50; 50),
712 insert: "foo!", 712 insert: "foo!($0)",
713 kind: Macro, 713 kind: Macro,
714 detail: "macro_rules! foo", 714 detail: "macro_rules! foo",
715 }, 715 },
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs
index 1b706bb13..5cabe9a32 100644
--- a/crates/ra_ide_api/src/completion/presentation.rs
+++ b/crates/ra_ide_api/src/completion/presentation.rs
@@ -109,12 +109,21 @@ impl Completions {
109 if let Some(name) = name { 109 if let Some(name) = name {
110 let detail = macro_label(&ast_node); 110 let detail = macro_label(&ast_node);
111 111
112 let builder = 112 let macro_braces_to_insert = match name.as_str() {
113 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.clone()) 113 "vec" => "[$0]",
114 .kind(CompletionItemKind::Macro) 114 _ => "($0)",
115 .set_documentation(macro_.docs(ctx.db)) 115 };
116 .detail(detail) 116 let macro_declaration = name + "!";
117 .insert_snippet(format!("{}!", name)); 117
118 let builder = CompletionItem::new(
119 CompletionKind::Reference,
120 ctx.source_range(),
121 &macro_declaration,
122 )
123 .kind(CompletionItemKind::Macro)
124 .set_documentation(macro_.docs(ctx.db))
125 .detail(detail)
126 .insert_snippet(macro_declaration + macro_braces_to_insert);
118 127
119 self.add(builder); 128 self.add(builder);
120 } 129 }