aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/completion
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src/completion')
-rw-r--r--crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs28
-rw-r--r--crates/ra_ide_api/src/completion/presentation.rs11
2 files changed, 36 insertions, 3 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 a08fb3b5c..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
@@ -47,4 +47,32 @@ mod tests {
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/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs
index 301c878b1..5cabe9a32 100644
--- a/crates/ra_ide_api/src/completion/presentation.rs
+++ b/crates/ra_ide_api/src/completion/presentation.rs
@@ -108,17 +108,22 @@ impl Completions {
108 let ast_node = macro_.source(ctx.db).ast; 108 let ast_node = macro_.source(ctx.db).ast;
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 let code_declaration = name + "!"; 111
112 let macro_braces_to_insert = match name.as_str() {
113 "vec" => "[$0]",
114 _ => "($0)",
115 };
116 let macro_declaration = name + "!";
112 117
113 let builder = CompletionItem::new( 118 let builder = CompletionItem::new(
114 CompletionKind::Reference, 119 CompletionKind::Reference,
115 ctx.source_range(), 120 ctx.source_range(),
116 &code_declaration, 121 &macro_declaration,
117 ) 122 )
118 .kind(CompletionItemKind::Macro) 123 .kind(CompletionItemKind::Macro)
119 .set_documentation(macro_.docs(ctx.db)) 124 .set_documentation(macro_.docs(ctx.db))
120 .detail(detail) 125 .detail(detail)
121 .insert_snippet(format!("{}($0)", &code_declaration)); 126 .insert_snippet(macro_declaration + macro_braces_to_insert);
122 127
123 self.add(builder); 128 self.add(builder);
124 } 129 }