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 a08fb3b5c1..6fcef4a729 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 @@ -44,6 +44,34 @@ mod tests { kind: Macro, detail: "macro_rules! foo", }, +]"## + ); + } + + #[test] + fn completes_vec_macros_with_square_brackets() { + assert_debug_snapshot!( + do_reference_completion( + " + //- /main.rs + macro_rules! vec { + () => {} + } + + fn foo() {} + + <|> + " + ), + @r##"[ + CompletionItem { + label: "vec!", + source_range: [46; 46), + delete: [46; 46), + insert: "vec![$0]", + kind: Macro, + detail: "macro_rules! vec", + }, ]"## ); } diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 301c878b1f..5cabe9a321 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 { let ast_node = macro_.source(ctx.db).ast; if let Some(name) = name { let detail = macro_label(&ast_node); - let code_declaration = name + "!"; + + let macro_braces_to_insert = match name.as_str() { + "vec" => "[$0]", + _ => "($0)", + }; + let macro_declaration = name + "!"; let builder = CompletionItem::new( CompletionKind::Reference, ctx.source_range(), - &code_declaration, + ¯o_declaration, ) .kind(CompletionItemKind::Macro) .set_documentation(macro_.docs(ctx.db)) .detail(detail) - .insert_snippet(format!("{}($0)", &code_declaration)); + .insert_snippet(macro_declaration + macro_braces_to_insert); self.add(builder); }