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