aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/completion
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-04-24 00:24:08 +0100
committerAleksey Kladov <[email protected]>2020-04-24 00:24:08 +0100
commit174952e89b891b20ea580f37e34389467fb9e23c (patch)
tree0b8ee196b3a096e68be5eeedf510b4a2eaf4864c /crates/ra_ide/src/completion
parent953b5f23cc493d75288cec1347ab65dd3ed38fd7 (diff)
Refactor
Diffstat (limited to 'crates/ra_ide/src/completion')
-rw-r--r--crates/ra_ide/src/completion/presentation.rs42
1 files changed, 18 insertions, 24 deletions
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs
index 6d8a5dc08..ab43d2a0a 100644
--- a/crates/ra_ide/src/completion/presentation.rs
+++ b/crates/ra_ide/src/completion/presentation.rs
@@ -307,42 +307,36 @@ impl Completions {
307 307
308pub(crate) fn compute_score( 308pub(crate) fn compute_score(
309 ctx: &CompletionContext, 309 ctx: &CompletionContext,
310 // FIXME: this definitely should be a `Type`
310 ty: &str, 311 ty: &str,
311 name: &str, 312 name: &str,
312) -> Option<CompletionScore> { 313) -> Option<CompletionScore> {
313 let (active_name, active_type) = if let Some(record_field) = &ctx.record_field_syntax { 314 let (active_name, active_type) = if let Some(record_field) = &ctx.record_field_syntax {
314 if let Some((struct_field, _)) = ctx.sema.resolve_record_field(record_field) { 315 let (struct_field, _local) = ctx.sema.resolve_record_field(record_field)?;
315 ( 316 (
316 struct_field.name(ctx.db).to_string(), 317 struct_field.name(ctx.db).to_string(),
317 struct_field.signature_ty(ctx.db).display(ctx.db).to_string(), 318 struct_field.signature_ty(ctx.db).display(ctx.db).to_string(),
318 ) 319 )
319 } else {
320 return None;
321 }
322 } else if let Some(call_info) = call_info(ctx.db, ctx.file_position) { 320 } else if let Some(call_info) = call_info(ctx.db, ctx.file_position) {
323 if call_info.active_parameter_type().is_some() 321 (call_info.active_parameter_name()?, call_info.active_parameter_type()?)
324 && call_info.active_parameter_name().is_some()
325 {
326 (call_info.active_parameter_name().unwrap(), call_info.active_parameter_type().unwrap())
327 } else {
328 return None;
329 }
330 } else { 322 } else {
331 return None; 323 return None;
332 }; 324 };
333 325
334 // Compute score 326 // Compute score
335 // For the same type 327 // For the same type
336 if &active_type == ty { 328 if &active_type != ty {
337 // If same type + same name then go top position 329 return None;
338 let res = if active_name == name { 330 }
339 CompletionScore::TypeAndNameMatch 331
340 } else { 332 let mut res = CompletionScore::TypeMatch;
341 CompletionScore::TypeMatch 333
342 }; 334 // If same type + same name then go top position
343 return Some(res); 335 if active_name == name {
336 res = CompletionScore::TypeAndNameMatch
344 } 337 }
345 None 338
339 Some(res)
346} 340}
347 341
348enum Params { 342enum Params {