aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-09-12 11:45:47 +0100
committerGitHub <[email protected]>2019-09-12 11:45:47 +0100
commit561e7aea5bdaf6c51e0a87da9ff1d73e2df52be1 (patch)
treeacb43ce2f904a5e79af45ff0706b9f69a273d210 /crates
parentdfcbdcb9a3a329686eedfc18518c675a6f80f338 (diff)
parent9c2a3da67cee6f941b4ad77bdb2b7552c8afdb7f (diff)
Merge #1821
1821: Macro completion tweaks r=matklad a=SomeoneToIgnore Thanks @uHOOCCOOHu for making the macro completion happen :) I've added a few tweaks to the current completion to make it a bit more convenient: * Automatically add braces and put the editor cursor inside of them: <img width="159" alt="image" src="https://user-images.githubusercontent.com/2690773/64737220-022b9f00-d4f5-11e9-8088-76d4678921ab.png"> Currently I have to add the braces manually which is a bit cumbersome. One further improvement can be to detect if macro accepts no parameters and place the cursor differently for this case. * Add an exclamation mark to the macro completion label This helps to distinguish macros from other completion items and also allows to show only macros in completion if you type `!`: <img width="722" alt="image" src="https://user-images.githubusercontent.com/2690773/64736987-8b8ea180-d4f4-11e9-8355-2ce4f83b7aa8.png"> <img width="732" alt="image" src="https://user-images.githubusercontent.com/2690773/64737214-ffc94500-d4f4-11e9-946e-1ba2db1c7fb1.png"> Additionally, automatic formatting hooks had adjusted two `help.rs` files, I've added them as a last commit to the PR even though they are not really related. Co-authored-by: Kirill Bulatov <[email protected]>
Diffstat (limited to 'crates')
-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
-rw-r--r--crates/ra_tools/src/help.rs90
5 files changed, 109 insertions, 72 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 }
diff --git a/crates/ra_tools/src/help.rs b/crates/ra_tools/src/help.rs
index 6dde6c2d2..9eb4dfbe4 100644
--- a/crates/ra_tools/src/help.rs
+++ b/crates/ra_tools/src/help.rs
@@ -1,45 +1,45 @@
1pub const GLOBAL_HELP: &str = "tasks 1pub const GLOBAL_HELP: &str = "tasks
2 2
3USAGE: 3USAGE:
4 ra_tools <SUBCOMMAND> 4 ra_tools <SUBCOMMAND>
5 5
6FLAGS: 6FLAGS:
7 -h, --help Prints help information 7 -h, --help Prints help information
8 8
9SUBCOMMANDS: 9SUBCOMMANDS:
10 format 10 format
11 format-hook 11 format-hook
12 fuzz-tests 12 fuzz-tests
13 gen-syntax 13 gen-syntax
14 gen-tests 14 gen-tests
15 install-ra 15 install-ra
16 lint"; 16 lint";
17 17
18pub const INSTALL_RA_HELP: &str = "ra_tools-install-ra 18pub const INSTALL_RA_HELP: &str = "ra_tools-install-ra
19 19
20USAGE: 20USAGE:
21 ra_tools.exe install-ra [FLAGS] 21 ra_tools.exe install-ra [FLAGS]
22 22
23FLAGS: 23FLAGS:
24 --client-code 24 --client-code
25 -h, --help Prints help information 25 -h, --help Prints help information
26 --jemalloc 26 --jemalloc
27 --server"; 27 --server";
28 28
29pub fn print_no_param_subcommand_help(subcommand: &str) { 29pub fn print_no_param_subcommand_help(subcommand: &str) {
30 eprintln!( 30 eprintln!(
31 "ra_tools-{} 31 "ra_tools-{}
32 32
33USAGE: 33USAGE:
34 ra_tools {} 34 ra_tools {}
35 35
36FLAGS: 36FLAGS:
37 -h, --help Prints help information", 37 -h, --help Prints help information",
38 subcommand, subcommand 38 subcommand, subcommand
39 ); 39 );
40} 40}
41 41
42pub const INSTALL_RA_CONFLICT: &str = 42pub const INSTALL_RA_CONFLICT: &str =
43 "error: The argument `--server` cannot be used with `--client-code` 43 "error: The argument `--server` cannot be used with `--client-code`
44 44
45For more information try --help"; 45For more information try --help";