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 708dc97771..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 @@ -37,13 +37,41 @@ mod tests { ), @r##"[ CompletionItem { - label: "foo", + label: "foo!", source_range: [46; 46), delete: [46; 46), - insert: "foo!", + insert: "foo!($0)", 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/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 31e7dffe8c..457a3d10c7 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 { ), @r###"[ CompletionItem { - label: "foo", + label: "foo!", source_range: [179; 179), delete: [179; 179), - insert: "foo!", + insert: "foo!($0)", kind: Macro, detail: "#[macro_export]\nmacro_rules! foo", }, diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index 2062e7300c..2ea22876f5 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 { ), @r##"[ CompletionItem { - label: "bar", + label: "bar!", source_range: [252; 252), delete: [252; 252), - insert: "bar!", + insert: "bar!($0)", kind: Macro, detail: "macro_rules! bar", }, CompletionItem { - label: "baz", + label: "baz!", source_range: [252; 252), delete: [252; 252), - insert: "baz!", + insert: "baz!($0)", kind: Macro, detail: "#[macro_export]\nmacro_rules! baz", }, CompletionItem { - label: "foo", + label: "foo!", source_range: [252; 252), delete: [252; 252), - insert: "foo!", + insert: "foo!($0)", kind: Macro, detail: "macro_rules! foo", }, @@ -633,14 +633,6 @@ mod tests { " ), @r##"[ - CompletionItem { - label: "foo", - source_range: [49; 49), - delete: [49; 49), - insert: "foo!", - kind: Macro, - detail: "macro_rules! foo", - }, CompletionItem { label: "foo", source_range: [49; 49), @@ -649,6 +641,14 @@ mod tests { kind: Function, detail: "fn foo()", }, + CompletionItem { + label: "foo!", + source_range: [49; 49), + delete: [49; 49), + insert: "foo!($0)", + kind: Macro, + detail: "macro_rules! foo", + }, ]"## ); } @@ -670,10 +670,10 @@ mod tests { ), @r##"[ CompletionItem { - label: "foo", + label: "foo!", source_range: [57; 57), delete: [57; 57), - insert: "foo!", + insert: "foo!($0)", kind: Macro, detail: "macro_rules! foo", }, @@ -706,10 +706,10 @@ mod tests { ), @r##"[ CompletionItem { - label: "foo", + label: "foo!", source_range: [50; 50), delete: [50; 50), - insert: "foo!", + insert: "foo!($0)", kind: Macro, detail: "macro_rules! foo", }, diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 1b706bb131..5cabe9a321 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 { if let Some(name) = name { let detail = macro_label(&ast_node); - let builder = - CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.clone()) - .kind(CompletionItemKind::Macro) - .set_documentation(macro_.docs(ctx.db)) - .detail(detail) - .insert_snippet(format!("{}!", 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(), + ¯o_declaration, + ) + .kind(CompletionItemKind::Macro) + .set_documentation(macro_.docs(ctx.db)) + .detail(detail) + .insert_snippet(macro_declaration + macro_braces_to_insert); self.add(builder); } diff --git a/crates/ra_tools/src/help.rs b/crates/ra_tools/src/help.rs index 6dde6c2d22..9eb4dfbe42 100644 --- a/crates/ra_tools/src/help.rs +++ b/crates/ra_tools/src/help.rs @@ -1,45 +1,45 @@ -pub const GLOBAL_HELP: &str = "tasks - -USAGE: - ra_tools - -FLAGS: - -h, --help Prints help information - -SUBCOMMANDS: - format - format-hook - fuzz-tests - gen-syntax - gen-tests - install-ra - lint"; - -pub const INSTALL_RA_HELP: &str = "ra_tools-install-ra - -USAGE: - ra_tools.exe install-ra [FLAGS] - -FLAGS: - --client-code - -h, --help Prints help information - --jemalloc - --server"; - -pub fn print_no_param_subcommand_help(subcommand: &str) { - eprintln!( - "ra_tools-{} - -USAGE: - ra_tools {} - -FLAGS: - -h, --help Prints help information", - subcommand, subcommand - ); -} - -pub const INSTALL_RA_CONFLICT: &str = - "error: The argument `--server` cannot be used with `--client-code` - -For more information try --help"; +pub const GLOBAL_HELP: &str = "tasks + +USAGE: + ra_tools + +FLAGS: + -h, --help Prints help information + +SUBCOMMANDS: + format + format-hook + fuzz-tests + gen-syntax + gen-tests + install-ra + lint"; + +pub const INSTALL_RA_HELP: &str = "ra_tools-install-ra + +USAGE: + ra_tools.exe install-ra [FLAGS] + +FLAGS: + --client-code + -h, --help Prints help information + --jemalloc + --server"; + +pub fn print_no_param_subcommand_help(subcommand: &str) { + eprintln!( + "ra_tools-{} + +USAGE: + ra_tools {} + +FLAGS: + -h, --help Prints help information", + subcommand, subcommand + ); +} + +pub const INSTALL_RA_CONFLICT: &str = + "error: The argument `--server` cannot be used with `--client-code` + +For more information try --help";