Complete vec macros with square brackets

This commit is contained in:
Kirill Bulatov 2019-09-12 01:27:50 +03:00
parent 2ca8ba783c
commit 9c2a3da67c
2 changed files with 36 additions and 3 deletions

View file

@ -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",
},
]"##
);
}

View file

@ -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,
&macro_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);
}