diff options
author | Kirill Bulatov <[email protected]> | 2019-09-11 23:27:50 +0100 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2019-09-12 10:16:09 +0100 |
commit | 9c2a3da67cee6f941b4ad77bdb2b7552c8afdb7f (patch) | |
tree | abd293149b37293108c6b3de2aee5eccc9dd551d /crates/ra_ide_api | |
parent | 2ca8ba783c8bea11152515380d403adb3df9b61c (diff) |
Complete vec macros with square brackets
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs | 28 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/presentation.rs | 11 |
2 files changed, 36 insertions, 3 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs b/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs index a08fb3b5c..6fcef4a72 100644 --- a/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs +++ b/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs | |||
@@ -47,4 +47,32 @@ mod tests { | |||
47 | ]"## | 47 | ]"## |
48 | ); | 48 | ); |
49 | } | 49 | } |
50 | |||
51 | #[test] | ||
52 | fn completes_vec_macros_with_square_brackets() { | ||
53 | assert_debug_snapshot!( | ||
54 | do_reference_completion( | ||
55 | " | ||
56 | //- /main.rs | ||
57 | macro_rules! vec { | ||
58 | () => {} | ||
59 | } | ||
60 | |||
61 | fn foo() {} | ||
62 | |||
63 | <|> | ||
64 | " | ||
65 | ), | ||
66 | @r##"[ | ||
67 | CompletionItem { | ||
68 | label: "vec!", | ||
69 | source_range: [46; 46), | ||
70 | delete: [46; 46), | ||
71 | insert: "vec![$0]", | ||
72 | kind: Macro, | ||
73 | detail: "macro_rules! vec", | ||
74 | }, | ||
75 | ]"## | ||
76 | ); | ||
77 | } | ||
50 | } | 78 | } |
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 301c878b1..5cabe9a32 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs | |||
@@ -108,17 +108,22 @@ impl Completions { | |||
108 | let ast_node = macro_.source(ctx.db).ast; | 108 | let ast_node = macro_.source(ctx.db).ast; |
109 | if let Some(name) = name { | 109 | if let Some(name) = name { |
110 | let detail = macro_label(&ast_node); | 110 | let detail = macro_label(&ast_node); |
111 | let code_declaration = name + "!"; | 111 | |
112 | let macro_braces_to_insert = match name.as_str() { | ||
113 | "vec" => "[$0]", | ||
114 | _ => "($0)", | ||
115 | }; | ||
116 | let macro_declaration = name + "!"; | ||
112 | 117 | ||
113 | let builder = CompletionItem::new( | 118 | let builder = CompletionItem::new( |
114 | CompletionKind::Reference, | 119 | CompletionKind::Reference, |
115 | ctx.source_range(), | 120 | ctx.source_range(), |
116 | &code_declaration, | 121 | ¯o_declaration, |
117 | ) | 122 | ) |
118 | .kind(CompletionItemKind::Macro) | 123 | .kind(CompletionItemKind::Macro) |
119 | .set_documentation(macro_.docs(ctx.db)) | 124 | .set_documentation(macro_.docs(ctx.db)) |
120 | .detail(detail) | 125 | .detail(detail) |
121 | .insert_snippet(format!("{}($0)", &code_declaration)); | 126 | .insert_snippet(macro_declaration + macro_braces_to_insert); |
122 | 127 | ||
123 | self.add(builder); | 128 | self.add(builder); |
124 | } | 129 | } |