From 037e02c08da80f25a6e0ddac06b36adac93f2076 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Thu, 12 Sep 2019 00:02:07 +0300 Subject: [PATCH 1/4] Complete macros parenthesis --- .../completion/complete_macro_in_item_position.rs | 2 +- crates/ra_ide_api/src/completion/complete_path.rs | 2 +- crates/ra_ide_api/src/completion/complete_scope.rs | 12 ++++++------ crates/ra_ide_api/src/completion/presentation.rs | 2 +- 4 files changed, 9 insertions(+), 9 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 708dc97771..dfba97f175 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 @@ -40,7 +40,7 @@ mod tests { label: "foo", source_range: [46; 46), delete: [46; 46), - insert: "foo!", + insert: "foo!($0)", kind: Macro, detail: "macro_rules! foo", }, diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 31e7dffe8c..465edf6dda 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -608,7 +608,7 @@ mod tests { 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..7380d8508e 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs @@ -571,7 +571,7 @@ mod tests { label: "bar", source_range: [252; 252), delete: [252; 252), - insert: "bar!", + insert: "bar!($0)", kind: Macro, detail: "macro_rules! bar", }, @@ -579,7 +579,7 @@ mod tests { label: "baz", source_range: [252; 252), delete: [252; 252), - insert: "baz!", + insert: "baz!($0)", kind: Macro, detail: "#[macro_export]\nmacro_rules! baz", }, @@ -587,7 +587,7 @@ mod tests { label: "foo", source_range: [252; 252), delete: [252; 252), - insert: "foo!", + insert: "foo!($0)", kind: Macro, detail: "macro_rules! foo", }, @@ -637,7 +637,7 @@ mod tests { label: "foo", source_range: [49; 49), delete: [49; 49), - insert: "foo!", + insert: "foo!($0)", kind: Macro, detail: "macro_rules! foo", }, @@ -673,7 +673,7 @@ mod tests { label: "foo", source_range: [57; 57), delete: [57; 57), - insert: "foo!", + insert: "foo!($0)", kind: Macro, detail: "macro_rules! foo", }, @@ -709,7 +709,7 @@ mod tests { 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..1995e89712 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs @@ -114,7 +114,7 @@ impl Completions { .kind(CompletionItemKind::Macro) .set_documentation(macro_.docs(ctx.db)) .detail(detail) - .insert_snippet(format!("{}!", name)); + .insert_snippet(format!("{}!($0)", name)); self.add(builder); } From 1852b272334b436865cb36089a91b5dba3148c7f Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Thu, 12 Sep 2019 00:24:39 +0300 Subject: [PATCH 2/4] Add `!` to the macro completion label --- .../complete_macro_in_item_position.rs | 2 +- .../src/completion/complete_path.rs | 2 +- .../src/completion/complete_scope.rs | 26 +++++++++---------- .../ra_ide_api/src/completion/presentation.rs | 16 +++++++----- 4 files changed, 25 insertions(+), 21 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 dfba97f175..a08fb3b5c1 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,7 +37,7 @@ mod tests { ), @r##"[ CompletionItem { - label: "foo", + label: "foo!", source_range: [46; 46), delete: [46; 46), insert: "foo!($0)", diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 465edf6dda..457a3d10c7 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -605,7 +605,7 @@ mod tests { ), @r###"[ CompletionItem { - label: "foo", + label: "foo!", source_range: [179; 179), delete: [179; 179), insert: "foo!($0)", diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index 7380d8508e..2ea22876f5 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs @@ -568,7 +568,7 @@ mod tests { ), @r##"[ CompletionItem { - label: "bar", + label: "bar!", source_range: [252; 252), delete: [252; 252), insert: "bar!($0)", @@ -576,7 +576,7 @@ mod tests { detail: "macro_rules! bar", }, CompletionItem { - label: "baz", + label: "baz!", source_range: [252; 252), delete: [252; 252), insert: "baz!($0)", @@ -584,7 +584,7 @@ mod tests { detail: "#[macro_export]\nmacro_rules! baz", }, CompletionItem { - label: "foo", + label: "foo!", source_range: [252; 252), delete: [252; 252), insert: "foo!($0)", @@ -633,14 +633,6 @@ mod tests { " ), @r##"[ - CompletionItem { - label: "foo", - source_range: [49; 49), - delete: [49; 49), - insert: "foo!($0)", - 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,7 +670,7 @@ mod tests { ), @r##"[ CompletionItem { - label: "foo", + label: "foo!", source_range: [57; 57), delete: [57; 57), insert: "foo!($0)", @@ -706,7 +706,7 @@ mod tests { ), @r##"[ CompletionItem { - label: "foo", + label: "foo!", source_range: [50; 50), delete: [50; 50), insert: "foo!($0)", diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 1995e89712..301c878b1f 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs @@ -108,13 +108,17 @@ 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 builder = - CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.clone()) - .kind(CompletionItemKind::Macro) - .set_documentation(macro_.docs(ctx.db)) - .detail(detail) - .insert_snippet(format!("{}!($0)", name)); + let builder = CompletionItem::new( + CompletionKind::Reference, + ctx.source_range(), + &code_declaration, + ) + .kind(CompletionItemKind::Macro) + .set_documentation(macro_.docs(ctx.db)) + .detail(detail) + .insert_snippet(format!("{}($0)", &code_declaration)); self.add(builder); } From 2ca8ba783c8bea11152515380d403adb3df9b61c Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Thu, 12 Sep 2019 12:15:52 +0300 Subject: [PATCH 3/4] Fix the formatting issues --- crates/ra_tools/src/help.rs | 90 ++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 45 deletions(-) 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"; From 9c2a3da67cee6f941b4ad77bdb2b7552c8afdb7f Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Thu, 12 Sep 2019 01:27:50 +0300 Subject: [PATCH 4/4] Complete vec macros with square brackets --- .../complete_macro_in_item_position.rs | 28 +++++++++++++++++++ .../ra_ide_api/src/completion/presentation.rs | 11 ++++++-- 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 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); }