@@ -15,19 +15,10 @@ namespace ts {
15
15
// better than substring matches which are better than CamelCase matches.
16
16
kind : PatternMatchKind ;
17
17
18
- // If this was a camel case match, how strong the match is. Higher number means
19
- // it was a better match.
20
- camelCaseWeight ?: number ;
21
-
22
18
// If this was a match where all constituent parts of the candidate and search pattern
23
19
// matched case sensitively or case insensitively. Case sensitive matches of the kind
24
20
// are better matches than insensitive matches.
25
21
isCaseSensitive : boolean ;
26
-
27
- // Whether or not this match occurred with the punctuation from the search pattern stripped
28
- // out or not. Matches without the punctuation stripped are better than ones with punctuation
29
- // stripped.
30
- punctuationStripped : boolean ;
31
22
}
32
23
33
24
// The pattern matcher maintains an internal cache of information as it is used. Therefore,
@@ -99,12 +90,10 @@ namespace ts {
99
90
characterSpans : TextSpan [ ] ;
100
91
}
101
92
102
- function createPatternMatch ( kind : PatternMatchKind , punctuationStripped : boolean , isCaseSensitive : boolean , camelCaseWeight ?: number ) : PatternMatch {
93
+ function createPatternMatch ( kind : PatternMatchKind , isCaseSensitive : boolean ) : PatternMatch {
103
94
return {
104
95
kind,
105
- punctuationStripped,
106
- isCaseSensitive,
107
- camelCaseWeight
96
+ isCaseSensitive
108
97
} ;
109
98
}
110
99
@@ -195,18 +184,18 @@ namespace ts {
195
184
return spans ;
196
185
}
197
186
198
- function matchTextChunk ( candidate : string , chunk : TextChunk , punctuationStripped : boolean ) : PatternMatch {
187
+ function matchTextChunk ( candidate : string , chunk : TextChunk ) : PatternMatch {
199
188
const index = indexOfIgnoringCase ( candidate , chunk . textLowerCase ) ;
200
189
if ( index === 0 ) {
201
190
if ( chunk . text . length === candidate . length ) {
202
191
// a) Check if the part matches the candidate entirely, in an case insensitive or
203
192
// sensitive manner. If it does, return that there was an exact match.
204
- return createPatternMatch ( PatternMatchKind . exact , punctuationStripped , /*isCaseSensitive:*/ candidate === chunk . text ) ;
193
+ return createPatternMatch ( PatternMatchKind . exact , /*isCaseSensitive:*/ candidate === chunk . text ) ;
205
194
}
206
195
else {
207
196
// b) Check if the part is a prefix of the candidate, in a case insensitive or sensitive
208
197
// manner. If it does, return that there was a prefix match.
209
- return createPatternMatch ( PatternMatchKind . prefix , punctuationStripped , /*isCaseSensitive:*/ startsWith ( candidate , chunk . text ) ) ;
198
+ return createPatternMatch ( PatternMatchKind . prefix , /*isCaseSensitive:*/ startsWith ( candidate , chunk . text ) ) ;
210
199
}
211
200
}
212
201
@@ -223,8 +212,7 @@ namespace ts {
223
212
const wordSpans = getWordSpans ( candidate ) ;
224
213
for ( const span of wordSpans ) {
225
214
if ( partStartsWith ( candidate , span , chunk . text , /*ignoreCase:*/ true ) ) {
226
- return createPatternMatch ( PatternMatchKind . substring , punctuationStripped ,
227
- /*isCaseSensitive:*/ partStartsWith ( candidate , span , chunk . text , /*ignoreCase:*/ false ) ) ;
215
+ return createPatternMatch ( PatternMatchKind . substring , /*isCaseSensitive:*/ partStartsWith ( candidate , span , chunk . text , /*ignoreCase:*/ false ) ) ;
228
216
}
229
217
}
230
218
}
@@ -234,22 +222,18 @@ namespace ts {
234
222
// candidate in a case *sensitive* manner. If so, return that there was a substring
235
223
// match.
236
224
if ( candidate . indexOf ( chunk . text ) > 0 ) {
237
- return createPatternMatch ( PatternMatchKind . substring , punctuationStripped , /*isCaseSensitive:*/ true ) ;
225
+ return createPatternMatch ( PatternMatchKind . substring , /*isCaseSensitive:*/ true ) ;
238
226
}
239
227
}
240
228
241
229
if ( ! isLowercase ) {
242
230
// e) If the part was not entirely lowercase, then attempt a camel cased match as well.
243
231
if ( chunk . characterSpans . length > 0 ) {
244
232
const candidateParts = getWordSpans ( candidate ) ;
245
- let camelCaseWeight = tryCamelCaseMatch ( candidate , candidateParts , chunk , /*ignoreCase:*/ false ) ;
246
- if ( camelCaseWeight !== undefined ) {
247
- return createPatternMatch ( PatternMatchKind . camelCase , punctuationStripped , /*isCaseSensitive:*/ true , /*camelCaseWeight:*/ camelCaseWeight ) ;
248
- }
249
-
250
- camelCaseWeight = tryCamelCaseMatch ( candidate , candidateParts , chunk , /*ignoreCase:*/ true ) ;
251
- if ( camelCaseWeight !== undefined ) {
252
- return createPatternMatch ( PatternMatchKind . camelCase , punctuationStripped , /*isCaseSensitive:*/ false , /*camelCaseWeight:*/ camelCaseWeight ) ;
233
+ const isCaseSensitive = tryCamelCaseMatch ( candidate , candidateParts , chunk , /*ignoreCase:*/ false ) ? true
234
+ : tryCamelCaseMatch ( candidate , candidateParts , chunk , /*ignoreCase:*/ true ) ? false : undefined ;
235
+ if ( isCaseSensitive !== undefined ) {
236
+ return createPatternMatch ( PatternMatchKind . camelCase , isCaseSensitive ) ;
253
237
}
254
238
}
255
239
}
@@ -264,7 +248,7 @@ namespace ts {
264
248
// (Pattern: fogbar, Candidate: quuxfogbarFogBar).
265
249
if ( chunk . text . length < candidate . length ) {
266
250
if ( index > 0 && isUpperCaseLetter ( candidate . charCodeAt ( index ) ) ) {
267
- return createPatternMatch ( PatternMatchKind . substring , punctuationStripped , /*isCaseSensitive:*/ false ) ;
251
+ return createPatternMatch ( PatternMatchKind . substring , /*isCaseSensitive:*/ false ) ;
268
252
}
269
253
}
270
254
}
@@ -292,7 +276,7 @@ namespace ts {
292
276
// Note: if the segment contains a space or an asterisk then we must assume that it's a
293
277
// multi-word segment.
294
278
if ( ! containsSpaceOrAsterisk ( segment . totalTextChunk . text ) ) {
295
- const match = matchTextChunk ( candidate , segment . totalTextChunk , /*punctuationStripped:*/ false ) ;
279
+ const match = matchTextChunk ( candidate , segment . totalTextChunk ) ;
296
280
if ( match ) {
297
281
return [ match ] ;
298
282
}
@@ -340,7 +324,7 @@ namespace ts {
340
324
341
325
for ( const subWordTextChunk of subWordTextChunks ) {
342
326
// Try to match the candidate with this word
343
- const result = matchTextChunk ( candidate , subWordTextChunk , /*punctuationStripped:*/ true ) ;
327
+ const result = matchTextChunk ( candidate , subWordTextChunk ) ;
344
328
if ( ! result ) {
345
329
return undefined ;
346
330
}
@@ -383,7 +367,7 @@ namespace ts {
383
367
return true ;
384
368
}
385
369
386
- function tryCamelCaseMatch ( candidate : string , candidateParts : TextSpan [ ] , chunk : TextChunk , ignoreCase : boolean ) : number {
370
+ function tryCamelCaseMatch ( candidate : string , candidateParts : TextSpan [ ] , chunk : TextChunk , ignoreCase : boolean ) : boolean {
387
371
const chunkCharacterSpans = chunk . characterSpans ;
388
372
389
373
// Note: we may have more pattern parts than candidate parts. This is because multiple
@@ -399,24 +383,11 @@ namespace ts {
399
383
while ( true ) {
400
384
// Let's consider our termination cases
401
385
if ( currentChunkSpan === chunkCharacterSpans . length ) {
402
- // We did match! We shall assign a weight to this
403
- let weight = 0 ;
404
-
405
- // Was this contiguous?
406
- if ( contiguous ) {
407
- weight += 1 ;
408
- }
409
-
410
- // Did we start at the beginning of the candidate?
411
- if ( firstMatch === 0 ) {
412
- weight += 2 ;
413
- }
414
-
415
- return weight ;
386
+ return true ;
416
387
}
417
388
else if ( currentCandidate === candidateParts . length ) {
418
389
// No match, since we still have more of the pattern to hit
419
- return undefined ;
390
+ return false ;
420
391
}
421
392
422
393
let candidatePart = candidateParts [ currentCandidate ] ;
0 commit comments