diff options
Diffstat (limited to 'crates/ra_ide/src/completion/presentation.rs')
-rw-r--r-- | crates/ra_ide/src/completion/presentation.rs | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index 78df9cbdb..5e2b8b920 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs | |||
@@ -114,17 +114,19 @@ impl Completions { | |||
114 | 114 | ||
115 | // Add `<>` for generic types | 115 | // Add `<>` for generic types |
116 | if ctx.is_path_type && !ctx.has_type_args && ctx.config.add_call_parenthesis { | 116 | if ctx.is_path_type && !ctx.has_type_args && ctx.config.add_call_parenthesis { |
117 | let has_non_default_type_params = match resolution { | 117 | if let Some(cap) = ctx.config.snippet_cap { |
118 | ScopeDef::ModuleDef(Adt(it)) => it.has_non_default_type_params(ctx.db), | 118 | let has_non_default_type_params = match resolution { |
119 | ScopeDef::ModuleDef(TypeAlias(it)) => it.has_non_default_type_params(ctx.db), | 119 | ScopeDef::ModuleDef(Adt(it)) => it.has_non_default_type_params(ctx.db), |
120 | _ => false, | 120 | ScopeDef::ModuleDef(TypeAlias(it)) => it.has_non_default_type_params(ctx.db), |
121 | }; | 121 | _ => false, |
122 | if has_non_default_type_params { | 122 | }; |
123 | tested_by!(inserts_angle_brackets_for_generics); | 123 | if has_non_default_type_params { |
124 | completion_item = completion_item | 124 | tested_by!(inserts_angle_brackets_for_generics); |
125 | .lookup_by(local_name.clone()) | 125 | completion_item = completion_item |
126 | .label(format!("{}<…>", local_name)) | 126 | .lookup_by(local_name.clone()) |
127 | .insert_snippet(format!("{}<$0>", local_name)); | 127 | .label(format!("{}<…>", local_name)) |
128 | .insert_snippet(cap, format!("{}<$0>", local_name)); | ||
129 | } | ||
128 | } | 130 | } |
129 | } | 131 | } |
130 | 132 | ||
@@ -184,13 +186,16 @@ impl Completions { | |||
184 | .set_deprecated(is_deprecated(macro_, ctx.db)) | 186 | .set_deprecated(is_deprecated(macro_, ctx.db)) |
185 | .detail(detail); | 187 | .detail(detail); |
186 | 188 | ||
187 | builder = if ctx.use_item_syntax.is_some() || ctx.is_macro_call { | 189 | builder = match ctx.config.snippet_cap { |
188 | tested_by!(dont_insert_macro_call_parens_unncessary); | 190 | Some(cap) if ctx.use_item_syntax.is_none() && !ctx.is_macro_call => { |
189 | builder.insert_text(name) | 191 | let macro_braces_to_insert = |
190 | } else { | 192 | self.guess_macro_braces(&name, docs.as_ref().map_or("", |s| s.as_str())); |
191 | let macro_braces_to_insert = | 193 | builder.insert_snippet(cap, macro_declaration + macro_braces_to_insert) |
192 | self.guess_macro_braces(&name, docs.as_ref().map_or("", |s| s.as_str())); | 194 | } |
193 | builder.insert_snippet(macro_declaration + macro_braces_to_insert) | 195 | _ => { |
196 | tested_by!(dont_insert_macro_call_parens_unncessary); | ||
197 | builder.insert_text(name) | ||
198 | } | ||
194 | }; | 199 | }; |
195 | 200 | ||
196 | self.add(builder); | 201 | self.add(builder); |
@@ -366,6 +371,10 @@ impl Builder { | |||
366 | if ctx.use_item_syntax.is_some() || ctx.is_call { | 371 | if ctx.use_item_syntax.is_some() || ctx.is_call { |
367 | return self; | 372 | return self; |
368 | } | 373 | } |
374 | let cap = match ctx.config.snippet_cap { | ||
375 | Some(it) => it, | ||
376 | None => return self, | ||
377 | }; | ||
369 | // If not an import, add parenthesis automatically. | 378 | // If not an import, add parenthesis automatically. |
370 | tested_by!(inserts_parens_for_function_calls); | 379 | tested_by!(inserts_parens_for_function_calls); |
371 | 380 | ||
@@ -387,7 +396,7 @@ impl Builder { | |||
387 | 396 | ||
388 | (snippet, format!("{}(…)", name)) | 397 | (snippet, format!("{}(…)", name)) |
389 | }; | 398 | }; |
390 | self.lookup_by(name).label(label).insert_snippet(snippet) | 399 | self.lookup_by(name).label(label).insert_snippet(cap, snippet) |
391 | } | 400 | } |
392 | } | 401 | } |
393 | 402 | ||