aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-10-30 07:40:23 +0000
committerGitHub <[email protected]>2019-10-30 07:40:23 +0000
commit8046f5b24a316a50e109fe484cde4c128293fa97 (patch)
tree296c398809c7905147ae1a55747462682347aac6 /crates
parent00bc907969117541c10fb7b16be45f0b9f7984ae (diff)
parentd7a7da8261795e15aef77ad306ada00c853fb913 (diff)
Merge #2125
2125: don't add macro braces in use items r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide_api/src/completion/presentation.rs70
1 files changed, 53 insertions, 17 deletions
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs
index aed4ce6d4..f7e98e6df 100644
--- a/crates/ra_ide_api/src/completion/presentation.rs
+++ b/crates/ra_ide_api/src/completion/presentation.rs
@@ -164,27 +164,32 @@ impl Completions {
164 name: Option<String>, 164 name: Option<String>,
165 macro_: hir::MacroDef, 165 macro_: hir::MacroDef,
166 ) { 166 ) {
167 let name = match name {
168 Some(it) => it,
169 None => return,
170 };
171
167 let ast_node = macro_.source(ctx.db).ast; 172 let ast_node = macro_.source(ctx.db).ast;
168 if let Some(name) = name { 173 let detail = macro_label(&ast_node);
169 let detail = macro_label(&ast_node); 174
175 let docs = macro_.docs(ctx.db);
176 let macro_declaration = format!("{}!", name);
177
178 let mut builder =
179 CompletionItem::new(CompletionKind::Reference, ctx.source_range(), &macro_declaration)
180 .kind(CompletionItemKind::Macro)
181 .set_documentation(docs.clone())
182 .detail(detail);
170 183
171 let docs = macro_.docs(ctx.db); 184 builder = if ctx.use_item_syntax.is_some() {
185 builder.insert_text(name)
186 } else {
172 let macro_braces_to_insert = 187 let macro_braces_to_insert =
173 self.guess_macro_braces(&name, docs.as_ref().map_or("", |s| s.as_str())); 188 self.guess_macro_braces(&name, docs.as_ref().map_or("", |s| s.as_str()));
174 let macro_declaration = name + "!"; 189 builder.insert_snippet(macro_declaration + macro_braces_to_insert)
175 190 };
176 let builder = CompletionItem::new(
177 CompletionKind::Reference,
178 ctx.source_range(),
179 &macro_declaration,
180 )
181 .kind(CompletionItemKind::Macro)
182 .set_documentation(docs)
183 .detail(detail)
184 .insert_snippet(macro_declaration + macro_braces_to_insert);
185 191
186 self.add(builder); 192 self.add(builder);
187 }
188 } 193 }
189 194
190 fn add_function_with_name( 195 fn add_function_with_name(
@@ -281,10 +286,11 @@ fn has_non_default_type_params(def: hir::GenericDef, db: &db::RootDatabase) -> b
281 286
282#[cfg(test)] 287#[cfg(test)]
283mod tests { 288mod tests {
284 use crate::completion::{do_completion, CompletionItem, CompletionKind};
285 use insta::assert_debug_snapshot; 289 use insta::assert_debug_snapshot;
286 use test_utils::covers; 290 use test_utils::covers;
287 291
292 use crate::completion::{do_completion, CompletionItem, CompletionKind};
293
288 fn do_reference_completion(code: &str) -> Vec<CompletionItem> { 294 fn do_reference_completion(code: &str) -> Vec<CompletionItem> {
289 do_completion(code, CompletionKind::Reference) 295 do_completion(code, CompletionKind::Reference)
290 } 296 }
@@ -576,4 +582,34 @@ mod tests {
576 "### 582 "###
577 ); 583 );
578 } 584 }
585
586 #[test]
587 fn dont_insert_macro_call_braces_in_use() {
588 assert_debug_snapshot!(
589 do_reference_completion(
590 r"
591 //- /main.rs
592 use foo::<|>;
593
594 //- /foo/lib.rs
595 #[macro_export]
596 macro_rules frobnicate {
597 () => ()
598 }
599 "
600 ),
601 @r###"
602 [
603 CompletionItem {
604 label: "frobnicate!",
605 source_range: [9; 9),
606 delete: [9; 9),
607 insert: "frobnicate",
608 kind: Macro,
609 detail: "#[macro_export]\nmacro_rules! frobnicate",
610 },
611 ]
612 "###
613 )
614 }
579} 615}