@@ -97,28 +97,22 @@ namespace ts {
97
97
} ;
98
98
}
99
99
100
- export function createPatternMatcher ( pattern : string ) : PatternMatcher {
100
+ export function createPatternMatcher ( pattern : string ) : PatternMatcher | undefined {
101
101
// We'll often see the same candidate string many times when searching (For example, when
102
102
// we see the name of a module that is used everywhere, or the name of an overload). As
103
103
// such, we cache the information we compute about the candidate for the life of this
104
104
// pattern matcher so we don't have to compute it multiple times.
105
105
const stringToWordSpans = createMap < TextSpan [ ] > ( ) ;
106
106
107
- pattern = pattern . trim ( ) ;
108
-
109
- const dotSeparatedSegments = pattern . split ( "." ) . map ( p => createSegment ( p . trim ( ) ) ) ;
110
- const invalidPattern = dotSeparatedSegments . length === 0 || forEach ( dotSeparatedSegments , segmentIsInvalid ) ;
107
+ const dotSeparatedSegments = pattern . trim ( ) . split ( "." ) . map ( p => createSegment ( p . trim ( ) ) ) ;
108
+ // A segment is considered invalid if we couldn't find any words in it.
109
+ if ( dotSeparatedSegments . some ( segment => ! segment . subWordTextChunks . length ) ) return undefined ;
111
110
112
111
return {
113
- getMatches : ( containers , candidate ) => skipMatch ( candidate ) ? undefined : getMatches ( containers , candidate , dotSeparatedSegments , stringToWordSpans ) ,
114
- getMatchesForLastSegmentOfPattern : candidate => skipMatch ( candidate ) ? undefined : matchSegment ( candidate , lastOrUndefined ( dotSeparatedSegments ) , stringToWordSpans ) ,
112
+ getMatches : ( containers , candidate ) => getMatches ( containers , candidate , dotSeparatedSegments , stringToWordSpans ) ,
113
+ getMatchesForLastSegmentOfPattern : candidate => matchSegment ( candidate , last ( dotSeparatedSegments ) , stringToWordSpans ) ,
115
114
patternContainsDots : dotSeparatedSegments . length > 1
116
115
} ;
117
-
118
- // Quick checks so we can bail out when asked to match a candidate.
119
- function skipMatch ( candidate : string ) {
120
- return invalidPattern || ! candidate ;
121
- }
122
116
}
123
117
124
118
function getMatches ( candidateContainers : ReadonlyArray < string > , candidate : string , dotSeparatedSegments : ReadonlyArray < Segment > , stringToWordSpans : Map < TextSpan [ ] > ) : PatternMatch [ ] | undefined {
@@ -381,11 +375,6 @@ namespace ts {
381
375
} ;
382
376
}
383
377
384
- // A segment is considered invalid if we couldn't find any words in it.
385
- function segmentIsInvalid ( segment : Segment ) {
386
- return segment . subWordTextChunks . length === 0 ;
387
- }
388
-
389
378
function isUpperCaseLetter ( ch : number ) {
390
379
// Fast check for the ascii range.
391
380
if ( ch >= CharacterCodes . A && ch <= CharacterCodes . Z ) {
0 commit comments