mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 05:53:45 +00:00
Complete vec macros with square brackets
This commit is contained in:
parent
2ca8ba783c
commit
9c2a3da67c
2 changed files with 36 additions and 3 deletions
|
@ -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",
|
||||
},
|
||||
]"##
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue