aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_ide/src/completion/completion_item.rs4
-rw-r--r--crates/ra_ide/src/completion/presentation.rs25
2 files changed, 18 insertions, 11 deletions
diff --git a/crates/ra_ide/src/completion/completion_item.rs b/crates/ra_ide/src/completion/completion_item.rs
index ea1e0433c..687b380bb 100644
--- a/crates/ra_ide/src/completion/completion_item.rs
+++ b/crates/ra_ide/src/completion/completion_item.rs
@@ -93,7 +93,7 @@ impl fmt::Debug for CompletionItem {
93 } 93 }
94} 94}
95 95
96#[derive(Debug, Clone)] 96#[derive(Debug, Clone, Copy)]
97pub enum CompletionScore { 97pub enum CompletionScore {
98 /// If only type match 98 /// If only type match
99 TypeMatch, 99 TypeMatch,
@@ -202,7 +202,7 @@ impl CompletionItem {
202 } 202 }
203 203
204 pub fn score(&self) -> Option<CompletionScore> { 204 pub fn score(&self) -> Option<CompletionScore> {
205 self.score.clone() 205 self.score
206 } 206 }
207 207
208 pub fn set_score(&mut self, score: CompletionScore) { 208 pub fn set_score(&mut self, score: CompletionScore) {
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs
index f8dac1d54..5aedfc47f 100644
--- a/crates/ra_ide/src/completion/presentation.rs
+++ b/crates/ra_ide/src/completion/presentation.rs
@@ -34,7 +34,9 @@ impl Completions {
34 .set_deprecated(is_deprecated) 34 .set_deprecated(is_deprecated)
35 .build(); 35 .build();
36 36
37 compute_score(&mut completion_item, ctx); 37 if let Some(score) = compute_score(&completion_item, ctx) {
38 completion_item.set_score(score);
39 }
38 40
39 self.add(completion_item); 41 self.add(completion_item);
40 } 42 }
@@ -305,7 +307,10 @@ impl Completions {
305 } 307 }
306} 308}
307 309
308pub(crate) fn compute_score(completion_item: &mut CompletionItem, ctx: &CompletionContext) { 310pub(crate) fn compute_score(
311 completion_item: &CompletionItem,
312 ctx: &CompletionContext,
313) -> Option<CompletionScore> {
309 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 {
310 if let Some((struct_field, _)) = ctx.sema.resolve_record_field(record_field) { 315 if let Some((struct_field, _)) = ctx.sema.resolve_record_field(record_field) {
311 ( 316 (
@@ -313,7 +318,7 @@ pub(crate) fn compute_score(completion_item: &mut CompletionItem, ctx: &Completi
313 struct_field.signature_ty(ctx.db).display(ctx.db).to_string(), 318 struct_field.signature_ty(ctx.db).display(ctx.db).to_string(),
314 ) 319 )
315 } else { 320 } else {
316 return; 321 return None;
317 } 322 }
318 } else if let Some(call_info) = call_info(ctx.db, ctx.file_position) { 323 } else if let Some(call_info) = call_info(ctx.db, ctx.file_position) {
319 if call_info.active_parameter_type().is_some() 324 if call_info.active_parameter_type().is_some()
@@ -321,10 +326,10 @@ pub(crate) fn compute_score(completion_item: &mut CompletionItem, ctx: &Completi
321 { 326 {
322 (call_info.active_parameter_name().unwrap(), call_info.active_parameter_type().unwrap()) 327 (call_info.active_parameter_name().unwrap(), call_info.active_parameter_type().unwrap())
323 } else { 328 } else {
324 return; 329 return None;
325 } 330 }
326 } else { 331 } else {
327 return; 332 return None;
328 }; 333 };
329 334
330 // Compute score 335 // Compute score
@@ -332,13 +337,15 @@ pub(crate) fn compute_score(completion_item: &mut CompletionItem, ctx: &Completi
332 if let Some(a_parameter_type) = completion_item.detail() { 337 if let Some(a_parameter_type) = completion_item.detail() {
333 if &active_type == a_parameter_type { 338 if &active_type == a_parameter_type {
334 // If same type + same name then go top position 339 // If same type + same name then go top position
335 if active_name == completion_item.label() { 340 let res = if active_name == completion_item.label() {
336 completion_item.set_score(CompletionScore::TypeAndNameMatch); 341 CompletionScore::TypeAndNameMatch
337 } else { 342 } else {
338 completion_item.set_score(CompletionScore::TypeMatch); 343 CompletionScore::TypeMatch
339 } 344 };
345 return Some(res);
340 } 346 }
341 } 347 }
348 None
342} 349}
343 350
344enum Params { 351enum Params {