aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/completion
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-03-28 10:01:25 +0000
committerAleksey Kladov <[email protected]>2020-03-28 10:01:25 +0000
commitb764c38436fcb9426eb7da3be4f5fbcd63b316f5 (patch)
treea599f1ffff953040a0c2bb635b33b0f6a57e5e59 /crates/ra_ide/src/completion
parenta1fea0d34ee8f3436aefd87d4c133a7ff50ffbb0 (diff)
Start stdx
This crate will hold everything to small to be worth publishing
Diffstat (limited to 'crates/ra_ide/src/completion')
-rw-r--r--crates/ra_ide/src/completion/presentation.rs45
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
3use hir::{Docs, HasAttrs, HasSource, HirDisplay, ScopeDef, StructKind, Type}; 3use hir::{Docs, HasAttrs, HasSource, HirDisplay, ScopeDef, StructKind, Type};
4use join_to_string::join;
5use ra_syntax::ast::NameOwner; 4use ra_syntax::ast::NameOwner;
5use stdx::SepBy;
6use test_utils::tested_by; 6use test_utils::tested_by;
7 7
8use crate::completion::{
9 CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions,
10};
11
12use crate::{ 8use 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)