Add ! to the macro completion label

This commit is contained in:
Kirill Bulatov 2019-09-12 00:24:39 +03:00
parent 037e02c08d
commit 1852b27233
4 changed files with 25 additions and 21 deletions

View file

@ -37,7 +37,7 @@ mod tests {
), ),
@r##"[ @r##"[
CompletionItem { CompletionItem {
label: "foo", label: "foo!",
source_range: [46; 46), source_range: [46; 46),
delete: [46; 46), delete: [46; 46),
insert: "foo!($0)", insert: "foo!($0)",

View file

@ -605,7 +605,7 @@ mod tests {
), ),
@r###"[ @r###"[
CompletionItem { CompletionItem {
label: "foo", label: "foo!",
source_range: [179; 179), source_range: [179; 179),
delete: [179; 179), delete: [179; 179),
insert: "foo!($0)", insert: "foo!($0)",

View file

@ -568,7 +568,7 @@ mod tests {
), ),
@r##"[ @r##"[
CompletionItem { CompletionItem {
label: "bar", label: "bar!",
source_range: [252; 252), source_range: [252; 252),
delete: [252; 252), delete: [252; 252),
insert: "bar!($0)", insert: "bar!($0)",
@ -576,7 +576,7 @@ mod tests {
detail: "macro_rules! bar", detail: "macro_rules! bar",
}, },
CompletionItem { CompletionItem {
label: "baz", label: "baz!",
source_range: [252; 252), source_range: [252; 252),
delete: [252; 252), delete: [252; 252),
insert: "baz!($0)", insert: "baz!($0)",
@ -584,7 +584,7 @@ mod tests {
detail: "#[macro_export]\nmacro_rules! baz", detail: "#[macro_export]\nmacro_rules! baz",
}, },
CompletionItem { CompletionItem {
label: "foo", label: "foo!",
source_range: [252; 252), source_range: [252; 252),
delete: [252; 252), delete: [252; 252),
insert: "foo!($0)", insert: "foo!($0)",
@ -633,14 +633,6 @@ mod tests {
" "
), ),
@r##"[ @r##"[
CompletionItem {
label: "foo",
source_range: [49; 49),
delete: [49; 49),
insert: "foo!($0)",
kind: Macro,
detail: "macro_rules! foo",
},
CompletionItem { CompletionItem {
label: "foo", label: "foo",
source_range: [49; 49), source_range: [49; 49),
@ -649,6 +641,14 @@ mod tests {
kind: Function, kind: Function,
detail: "fn foo()", detail: "fn foo()",
}, },
CompletionItem {
label: "foo!",
source_range: [49; 49),
delete: [49; 49),
insert: "foo!($0)",
kind: Macro,
detail: "macro_rules! foo",
},
]"## ]"##
); );
} }
@ -670,7 +670,7 @@ mod tests {
), ),
@r##"[ @r##"[
CompletionItem { CompletionItem {
label: "foo", label: "foo!",
source_range: [57; 57), source_range: [57; 57),
delete: [57; 57), delete: [57; 57),
insert: "foo!($0)", insert: "foo!($0)",
@ -706,7 +706,7 @@ mod tests {
), ),
@r##"[ @r##"[
CompletionItem { CompletionItem {
label: "foo", label: "foo!",
source_range: [50; 50), source_range: [50; 50),
delete: [50; 50), delete: [50; 50),
insert: "foo!($0)", insert: "foo!($0)",

View file

@ -108,13 +108,17 @@ 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 builder = let builder = CompletionItem::new(
CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.clone()) CompletionKind::Reference,
.kind(CompletionItemKind::Macro) ctx.source_range(),
.set_documentation(macro_.docs(ctx.db)) &code_declaration,
.detail(detail) )
.insert_snippet(format!("{}!($0)", name)); .kind(CompletionItemKind::Macro)
.set_documentation(macro_.docs(ctx.db))
.detail(detail)
.insert_snippet(format!("{}($0)", &code_declaration));
self.add(builder); self.add(builder);
} }