@@ -430,18 +430,25 @@ class CodeCompletionSession {
430
430
let notRecommended = ( value [ sourcekitd. keys. notRecommended] ?? 0 ) != 0
431
431
432
432
let sortText : String ?
433
- if let semanticScore: Double = value [ sourcekitd. keys. semanticScore] {
433
+ if let semanticScore: Double = value [ sourcekitd. keys. semanticScore] ,
434
+ let textMatchScore: Double = value [ sourcekitd. keys. textMatchScore]
435
+ {
436
+ let score = semanticScore * textMatchScore
434
437
// sourcekitd returns numeric completion item scores with a higher score being better. LSP's sort text is
435
438
// lexicographical. Map the numeric score to a lexicographically sortable score by subtracting it from 5_000.
436
439
// This gives us a valid range of semantic scores from -5_000 to 5_000 that can be sorted correctly
437
440
// lexicographically. This should be sufficient as semantic scores are typically single-digit.
438
- var lexicallySortableScore = 5_000 - semanticScore
441
+ var lexicallySortableScore = 5_000 - score
439
442
if lexicallySortableScore < 0 {
440
- logger. fault ( " Semantic score out-of-bounds: \( semanticScore, privacy: . public) " )
443
+ logger. fault (
444
+ " score out-of-bounds: \( score, privacy: . public) , semantic: \( semanticScore, privacy: . public) , textual: \( textMatchScore, privacy: . public) "
445
+ )
441
446
lexicallySortableScore = 0
442
447
}
443
448
if lexicallySortableScore >= 10_000 {
444
- logger. fault ( " Semantic score out-of-bounds: \( semanticScore, privacy: . public) " )
449
+ logger. fault (
450
+ " score out-of-bounds: \( score, privacy: . public) , semantic: \( semanticScore, privacy: . public) , textual: \( textMatchScore, privacy: . public) "
451
+ )
445
452
lexicallySortableScore = 9_999.99999999
446
453
}
447
454
sortText = String ( format: " %013.8f " , lexicallySortableScore) + " - \( name) "
0 commit comments