@@ -430,18 +430,25 @@ class CodeCompletionSession {
430430 let notRecommended = ( value [ sourcekitd. keys. notRecommended] ?? 0 ) != 0
431431
432432 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
434437 // sourcekitd returns numeric completion item scores with a higher score being better. LSP's sort text is
435438 // lexicographical. Map the numeric score to a lexicographically sortable score by subtracting it from 5_000.
436439 // This gives us a valid range of semantic scores from -5_000 to 5_000 that can be sorted correctly
437440 // lexicographically. This should be sufficient as semantic scores are typically single-digit.
438- var lexicallySortableScore = 5_000 - semanticScore
441+ var lexicallySortableScore = 5_000 - score
439442 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+ )
441446 lexicallySortableScore = 0
442447 }
443448 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+ )
445452 lexicallySortableScore = 9_999.99999999
446453 }
447454 sortText = String ( format: " %013.8f " , lexicallySortableScore) + " - \( name) "
0 commit comments