66'use strict' ;
77
88import { compareAnything } from 'vs/base/common/comparers' ;
9- import { matchesPrefix , IMatch , createMatches , matchesCamelCase , isSeparatorAtPos , isUpper } from 'vs/base/common/filters' ;
9+ import { matchesPrefix , IMatch , createMatches , matchesCamelCase , isUpper } from 'vs/base/common/filters' ;
1010import { isEqual , nativeSep } from 'vs/base/common/paths' ;
1111import { isWindows } from 'vs/base/common/platform' ;
1212import { stripWildcards } from 'vs/base/common/strings' ;
13+ import { CharCode } from 'vs/base/common/charCode' ;
1314
1415export type Score = [ number /* score */ , number [ ] /* match positions */ ] ;
1516export type ScorerCache = { [ key : string ] : IItemScore } ;
@@ -189,22 +190,26 @@ function computeCharScore(query: string, queryLower: string, queryIndex: number,
189190 // }
190191 }
191192
192- // After separator bonus
193- else if ( isSeparatorAtPos ( target , targetIndex - 1 ) ) {
194- score += 4 ;
193+ else {
195194
196- // if (DEBUG) {
197- // console.log('After separtor bonus: +4' );
198- // }
199- }
195+ // After separator bonus
196+ const separatorBonus = scoreSeparatorAtPos ( target . charCodeAt ( targetIndex - 1 ) ) ;
197+ if ( separatorBonus ) {
198+ score += separatorBonus ;
200199
201- // Inside word upper case bonus
202- else if ( isUpper ( target . charCodeAt ( targetIndex ) ) ) {
203- score += 1 ;
200+ // if (DEBUG) {
201+ // console.log('After separtor bonus: +4');
202+ // }
203+ }
204204
205- // if (DEBUG) {
206- // console.log('Inside word upper case bonus: +1');
207- // }
205+ // Inside word upper case bonus (camel case)
206+ else if ( isUpper ( target . charCodeAt ( targetIndex ) ) ) {
207+ score += 1 ;
208+
209+ // if (DEBUG) {
210+ // console.log('Inside word upper case bonus: +1');
211+ // }
212+ }
208213 }
209214
210215 // if (DEBUG) {
@@ -214,6 +219,24 @@ function computeCharScore(query: string, queryLower: string, queryIndex: number,
214219 return score ;
215220}
216221
222+ function scoreSeparatorAtPos ( charCode : number ) : number {
223+ switch ( charCode ) {
224+ case CharCode . Slash :
225+ case CharCode . Backslash :
226+ return 5 ; // prefer path separators...
227+ case CharCode . Underline :
228+ case CharCode . Dash :
229+ case CharCode . Period :
230+ case CharCode . Space :
231+ case CharCode . SingleQuote :
232+ case CharCode . DoubleQuote :
233+ case CharCode . Colon :
234+ return 4 ; // ...over other separators
235+ default :
236+ return 0 ;
237+ }
238+ }
239+
217240// function printMatrix(query: string, target: string, matches: number[], scores: number[]): void {
218241// console.log('\t' + target.split('').join('\t'));
219242// for (let queryIndex = 0; queryIndex < query.length; queryIndex++) {
0 commit comments