mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 22:13:39 +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,
|
kind: Macro,
|
||||||
detail: "macro_rules! foo",
|
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;
|
let ast_node = macro_.source(ctx.db).ast;
|
||||||
if let Some(name) = name {
|
if let Some(name) = name {
|
||||||
let detail = macro_label(&ast_node);
|
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(
|
let builder = CompletionItem::new(
|
||||||
CompletionKind::Reference,
|
CompletionKind::Reference,
|
||||||
ctx.source_range(),
|
ctx.source_range(),
|
||||||
&code_declaration,
|
¯o_declaration,
|
||||||
)
|
)
|
||||||
.kind(CompletionItemKind::Macro)
|
.kind(CompletionItemKind::Macro)
|
||||||
.set_documentation(macro_.docs(ctx.db))
|
.set_documentation(macro_.docs(ctx.db))
|
||||||
.detail(detail)
|
.detail(detail)
|
||||||
.insert_snippet(format!("{}($0)", &code_declaration));
|
.insert_snippet(macro_declaration + macro_braces_to_insert);
|
||||||
|
|
||||||
self.add(builder);
|
self.add(builder);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue