diff options
Diffstat (limited to 'crates/ra_ide/src/completion/presentation.rs')
-rw-r--r-- | crates/ra_ide/src/completion/presentation.rs | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index 253848602..60f1b83f3 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs | |||
@@ -1,15 +1,14 @@ | |||
1 | //! This modules takes care of rendering various definitions as completion items. | 1 | //! This modules takes care of rendering various definitions as completion items. |
2 | 2 | ||
3 | use hir::{Docs, HasAttrs, HasSource, HirDisplay, ScopeDef, StructKind, Type}; | 3 | use hir::{Docs, HasAttrs, HasSource, HirDisplay, ScopeDef, StructKind, Type}; |
4 | use join_to_string::join; | ||
5 | use ra_syntax::ast::NameOwner; | 4 | use ra_syntax::ast::NameOwner; |
5 | use stdx::SepBy; | ||
6 | use test_utils::tested_by; | 6 | use test_utils::tested_by; |
7 | 7 | ||
8 | use crate::completion::{ | ||
9 | CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions, | ||
10 | }; | ||
11 | |||
12 | use crate::{ | 8 | use crate::{ |
9 | completion::{ | ||
10 | CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions, | ||
11 | }, | ||
13 | display::{const_label, macro_label, type_label, FunctionSignature}, | 12 | display::{const_label, macro_label, type_label, FunctionSignature}, |
14 | RootDatabase, | 13 | RootDatabase, |
15 | }; | 14 | }; |
@@ -221,13 +220,13 @@ impl Completions { | |||
221 | builder = builder.trigger_call_info(); | 220 | builder = builder.trigger_call_info(); |
222 | let snippet = if ctx.options.add_call_argument_snippets { | 221 | let snippet = if ctx.options.add_call_argument_snippets { |
223 | let to_skip = if has_self_param { 1 } else { 0 }; | 222 | let to_skip = if has_self_param { 1 } else { 0 }; |
224 | let function_params_snippet = join( | 223 | let function_params_snippet = function_signature |
225 | function_signature.parameter_names.iter().skip(to_skip).enumerate().map( | 224 | .parameter_names |
226 | |(index, param_name)| format!("${{{}:{}}}", index + 1, param_name), | 225 | .iter() |
227 | ), | 226 | .skip(to_skip) |
228 | ) | 227 | .enumerate() |
229 | .separator(", ") | 228 | .map(|(index, param_name)| format!("${{{}:{}}}", index + 1, param_name)) |
230 | .to_string(); | 229 | .sep_by(", "); |
231 | format!("{}({})$0", name, function_params_snippet) | 230 | format!("{}({})$0", name, function_params_snippet) |
232 | } else { | 231 | } else { |
233 | format!("{}($0)", name) | 232 | format!("{}($0)", name) |
@@ -281,18 +280,16 @@ impl Completions { | |||
281 | .into_iter() | 280 | .into_iter() |
282 | .map(|field| (field.name(ctx.db), field.signature_ty(ctx.db))); | 281 | .map(|field| (field.name(ctx.db), field.signature_ty(ctx.db))); |
283 | let detail = match variant.kind(ctx.db) { | 282 | let detail = match variant.kind(ctx.db) { |
284 | StructKind::Tuple | StructKind::Unit => { | 283 | StructKind::Tuple | StructKind::Unit => detail_types |
285 | join(detail_types.map(|(_, t)| t.display(ctx.db).to_string())) | 284 | .map(|(_, t)| t.display(ctx.db).to_string()) |
286 | .separator(", ") | 285 | .sep_by(", ") |
287 | .surround_with("(", ")") | 286 | .surround_with("(", ")") |
288 | .to_string() | 287 | .to_string(), |
289 | } | 288 | StructKind::Record => detail_types |
290 | StructKind::Record => { | 289 | .map(|(n, t)| format!("{}: {}", n, t.display(ctx.db).to_string())) |
291 | join(detail_types.map(|(n, t)| format!("{}: {}", n, t.display(ctx.db).to_string()))) | 290 | .sep_by(", ") |
292 | .separator(", ") | 291 | .surround_with("{ ", " }") |
293 | .surround_with("{ ", " }") | 292 | .to_string(), |
294 | .to_string() | ||
295 | } | ||
296 | }; | 293 | }; |
297 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.to_string()) | 294 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.to_string()) |
298 | .kind(CompletionItemKind::EnumVariant) | 295 | .kind(CompletionItemKind::EnumVariant) |