@@ -242,7 +242,7 @@ impl CompletionRelevance {
242
242
/// See is_relevant if you need to make some judgement about score
243
243
/// in an absolute sense.
244
244
pub fn score ( self ) -> u32 {
245
- let mut score = 0 ;
245
+ let mut score = ! 0 / 2 ;
246
246
let CompletionRelevance {
247
247
exact_name_match,
248
248
type_match,
@@ -255,73 +255,69 @@ impl CompletionRelevance {
255
255
function,
256
256
} = self ;
257
257
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
+
258
268
// lower rank private things
259
269
if !is_private_editable {
260
270
score += 1 ;
261
271
}
262
272
263
273
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 ;
266
277
}
267
278
// lower rank trait op methods
268
- if ! trait_. is_op_method {
269
- score += 10 ;
279
+ if trait_. is_op_method {
280
+ score -= 5 ;
270
281
}
271
- } else {
272
- // lower rank trait op methods
273
- score += 10 ;
274
282
}
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 ;
282
286
}
283
287
if exact_name_match {
284
- score += 10 ;
288
+ score += 20 ;
285
289
}
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 => ( ) ,
290
294
} ;
291
295
score += match type_match {
292
- Some ( CompletionRelevanceTypeMatch :: Exact ) => 8 ,
293
- Some ( CompletionRelevanceTypeMatch :: CouldUnify ) => 3 ,
296
+ Some ( CompletionRelevanceTypeMatch :: Exact ) => 18 ,
297
+ Some ( CompletionRelevanceTypeMatch :: CouldUnify ) => 5 ,
294
298
None => 0 ,
295
299
} ;
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
+ }
321
318
322
- fn_score
323
- } )
324
- . unwrap_or_default ( ) ;
319
+ score += fn_score;
320
+ } ;
325
321
326
322
score
327
323
}
0 commit comments