@@ -242,7 +242,7 @@ impl CompletionRelevance {
242242 /// See is_relevant if you need to make some judgement about score
243243 /// in an absolute sense.
244244 pub fn score ( self ) -> u32 {
245- let mut score = 0 ;
245+ let mut score = ! 0 / 2 ;
246246 let CompletionRelevance {
247247 exact_name_match,
248248 type_match,
@@ -255,73 +255,69 @@ impl CompletionRelevance {
255255 function,
256256 } = self ;
257257
258+ // only applicable for completions within use items
259+ // lower rank for conflicting import names
260+ if is_name_already_imported {
261+ score -= 1 ;
262+ }
263+ // slightly prefer locals
264+ if is_local {
265+ score += 1 ;
266+ }
267+
258268 // lower rank private things
259269 if !is_private_editable {
260270 score += 1 ;
261271 }
262272
263273 if let Some ( trait_) = trait_ {
264- if trait_. notable_trait {
265- score += 1 ;
274+ // lower rank trait methods unless its notable
275+ if !trait_. notable_trait {
276+ score -= 5 ;
266277 }
267278 // lower rank trait op methods
268- if ! trait_. is_op_method {
269- score += 10 ;
279+ if trait_. is_op_method {
280+ score -= 5 ;
270281 }
271- } else {
272- // lower rank trait op methods
273- score += 10 ;
274282 }
275- // lower rank for conflicting import names
276- if !is_name_already_imported {
277- score += 1 ;
278- }
279- // lower rank for items that don't need an import
280- if !requires_import {
281- score += 1 ;
283+ // lower rank for items that need an import
284+ if requires_import {
285+ score -= 1 ;
282286 }
283287 if exact_name_match {
284- score += 10 ;
288+ score += 20 ;
285289 }
286- score += match postfix_match {
287- Some ( CompletionRelevancePostfixMatch :: Exact ) => 100 ,
288- Some ( CompletionRelevancePostfixMatch :: NonExact ) => 0 ,
289- None => 3 ,
290+ match postfix_match {
291+ Some ( CompletionRelevancePostfixMatch :: Exact ) => score += 100 ,
292+ Some ( CompletionRelevancePostfixMatch :: NonExact ) => score -= 5 ,
293+ None => ( ) ,
290294 } ;
291295 score += match type_match {
292- Some ( CompletionRelevanceTypeMatch :: Exact ) => 8 ,
293- Some ( CompletionRelevanceTypeMatch :: CouldUnify ) => 3 ,
296+ Some ( CompletionRelevanceTypeMatch :: Exact ) => 18 ,
297+ Some ( CompletionRelevanceTypeMatch :: CouldUnify ) => 5 ,
294298 None => 0 ,
295299 } ;
296- // slightly prefer locals
297- if is_local {
298- score += 1 ;
299- }
300- score += function
301- . map ( |asf| {
302- let mut fn_score = match asf. return_type {
303- CompletionRelevanceReturnType :: DirectConstructor => 15 ,
304- CompletionRelevanceReturnType :: Builder => 10 ,
305- CompletionRelevanceReturnType :: Constructor => 5 ,
306- CompletionRelevanceReturnType :: Other => 0 ,
307- } ;
308-
309- // When a fn is bumped due to return type:
310- // Bump Constructor or Builder methods with no arguments,
311- // over them than with self arguments
312- if fn_score > 0 {
313- if !asf. has_params {
314- // bump associated functions
315- fn_score += 1 ;
316- } else if asf. has_self_param {
317- // downgrade methods (below Constructor)
318- fn_score = 1 ;
319- }
320- }
300+ if let Some ( function) = function {
301+ let mut fn_score = match function. return_type {
302+ CompletionRelevanceReturnType :: DirectConstructor => 15 ,
303+ CompletionRelevanceReturnType :: Builder => 10 ,
304+ CompletionRelevanceReturnType :: Constructor => 5 ,
305+ CompletionRelevanceReturnType :: Other => 0u32 ,
306+ } ;
307+
308+ // When a fn is bumped due to return type:
309+ // Bump Constructor or Builder methods with no arguments,
310+ // over them than with self arguments
311+ if function. has_params {
312+ // bump associated functions
313+ fn_score = fn_score. saturating_sub ( 1 ) ;
314+ } else if function. has_self_param {
315+ // downgrade methods (below Constructor)
316+ fn_score = fn_score. min ( 1 ) ;
317+ }
321318
322- fn_score
323- } )
324- . unwrap_or_default ( ) ;
319+ score += fn_score;
320+ } ;
325321
326322 score
327323 }
0 commit comments