mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 05:53:45 +00:00
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 <mail4score@gmail.com>
This commit is contained in:
commit
561e7aea5b
5 changed files with 110 additions and 73 deletions
|
@ -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",
|
||||
},
|
||||
]"##
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
},
|
||||
|
|
|
@ -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",
|
||||
},
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -1,45 +1,45 @@
|
|||
pub const GLOBAL_HELP: &str = "tasks
|
||||
|
||||
USAGE:
|
||||
ra_tools <SUBCOMMAND>
|
||||
|
||||
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 <SUBCOMMAND>
|
||||
|
||||
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";
|
||||
|
|
Loading…
Reference in a new issue