diff options
Diffstat (limited to 'crates/ide_completion/src/item.rs')
-rw-r--r-- | crates/ide_completion/src/item.rs | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/crates/ide_completion/src/item.rs b/crates/ide_completion/src/item.rs index 3febab32b..9a4b5217a 100644 --- a/crates/ide_completion/src/item.rs +++ b/crates/ide_completion/src/item.rs | |||
@@ -144,6 +144,21 @@ pub struct CompletionRelevance { | |||
144 | /// } | 144 | /// } |
145 | /// ``` | 145 | /// ``` |
146 | pub exact_type_match: bool, | 146 | pub exact_type_match: bool, |
147 | /// This is set in cases like these: | ||
148 | /// | ||
149 | /// ``` | ||
150 | /// fn foo(bar: u32) { | ||
151 | /// $0 // `bar` is local | ||
152 | /// } | ||
153 | /// ``` | ||
154 | /// | ||
155 | /// ``` | ||
156 | /// fn foo() { | ||
157 | /// let bar = 0; | ||
158 | /// $0 // `bar` is local | ||
159 | /// } | ||
160 | /// ``` | ||
161 | pub is_local: bool, | ||
147 | } | 162 | } |
148 | 163 | ||
149 | impl CompletionRelevance { | 164 | impl CompletionRelevance { |
@@ -163,6 +178,9 @@ impl CompletionRelevance { | |||
163 | score += 1; | 178 | score += 1; |
164 | } | 179 | } |
165 | if self.exact_type_match { | 180 | if self.exact_type_match { |
181 | score += 3; | ||
182 | } | ||
183 | if self.is_local { | ||
166 | score += 1; | 184 | score += 1; |
167 | } | 185 | } |
168 | 186 | ||
@@ -551,9 +569,24 @@ mod tests { | |||
551 | vec![CompletionRelevance::default()], | 569 | vec![CompletionRelevance::default()], |
552 | vec![ | 570 | vec![ |
553 | CompletionRelevance { exact_name_match: true, ..CompletionRelevance::default() }, | 571 | CompletionRelevance { exact_name_match: true, ..CompletionRelevance::default() }, |
554 | CompletionRelevance { exact_type_match: true, ..CompletionRelevance::default() }, | 572 | CompletionRelevance { is_local: true, ..CompletionRelevance::default() }, |
555 | ], | 573 | ], |
556 | vec![CompletionRelevance { exact_name_match: true, exact_type_match: true }], | 574 | vec![CompletionRelevance { |
575 | exact_name_match: true, | ||
576 | is_local: true, | ||
577 | ..CompletionRelevance::default() | ||
578 | }], | ||
579 | vec![CompletionRelevance { exact_type_match: true, ..CompletionRelevance::default() }], | ||
580 | vec![CompletionRelevance { | ||
581 | exact_name_match: true, | ||
582 | exact_type_match: true, | ||
583 | ..CompletionRelevance::default() | ||
584 | }], | ||
585 | vec![CompletionRelevance { | ||
586 | exact_name_match: true, | ||
587 | exact_type_match: true, | ||
588 | is_local: true, | ||
589 | }], | ||
557 | ]; | 590 | ]; |
558 | 591 | ||
559 | check_relevance_score_ordered(expected_relevance_order); | 592 | check_relevance_score_ordered(expected_relevance_order); |