@@ -9,7 +9,7 @@ import * as strings from 'vs/base/common/strings';
99
1010export interface IFilter {
1111 // Returns null if word doesn't match.
12- ( word : string , wordToMatchAgainst : string ) : IMatch [ ] ;
12+ ( word : string , wordToMatchAgainst : string ) : IMatch [ ] | null ;
1313}
1414
1515export interface IMatch {
@@ -26,7 +26,7 @@ export interface IMatch {
2626 * filter.
2727 */
2828export function or ( ...filter : IFilter [ ] ) : IFilter {
29- return function ( word : string , wordToMatchAgainst : string ) : IMatch [ ] {
29+ return function ( word : string , wordToMatchAgainst : string ) : IMatch [ ] | null {
3030 for ( let i = 0 , len = filter . length ; i < len ; i ++ ) {
3131 let match = filter [ i ] ( word , wordToMatchAgainst ) ;
3232 if ( match ) {
@@ -42,7 +42,7 @@ export function or(...filter: IFilter[]): IFilter {
4242export const matchesStrictPrefix : IFilter = _matchesPrefix . bind ( undefined , false ) ;
4343export const matchesPrefix : IFilter = _matchesPrefix . bind ( undefined , true ) ;
4444
45- function _matchesPrefix ( ignoreCase : boolean , word : string , wordToMatchAgainst : string ) : IMatch [ ] {
45+ function _matchesPrefix ( ignoreCase : boolean , word : string , wordToMatchAgainst : string ) : IMatch [ ] | null {
4646 if ( ! wordToMatchAgainst || wordToMatchAgainst . length < word . length ) {
4747 return null ;
4848 }
@@ -63,7 +63,7 @@ function _matchesPrefix(ignoreCase: boolean, word: string, wordToMatchAgainst: s
6363
6464// Contiguous Substring
6565
66- export function matchesContiguousSubString ( word : string , wordToMatchAgainst : string ) : IMatch [ ] {
66+ export function matchesContiguousSubString ( word : string , wordToMatchAgainst : string ) : IMatch [ ] | null {
6767 let index = wordToMatchAgainst . toLowerCase ( ) . indexOf ( word . toLowerCase ( ) ) ;
6868 if ( index === - 1 ) {
6969 return null ;
@@ -74,18 +74,18 @@ export function matchesContiguousSubString(word: string, wordToMatchAgainst: str
7474
7575// Substring
7676
77- export function matchesSubString ( word : string , wordToMatchAgainst : string ) : IMatch [ ] {
77+ export function matchesSubString ( word : string , wordToMatchAgainst : string ) : IMatch [ ] | null {
7878 return _matchesSubString ( word . toLowerCase ( ) , wordToMatchAgainst . toLowerCase ( ) , 0 , 0 ) ;
7979}
8080
81- function _matchesSubString ( word : string , wordToMatchAgainst : string , i : number , j : number ) : IMatch [ ] {
81+ function _matchesSubString ( word : string , wordToMatchAgainst : string , i : number , j : number ) : IMatch [ ] | null {
8282 if ( i === word . length ) {
8383 return [ ] ;
8484 } else if ( j === wordToMatchAgainst . length ) {
8585 return null ;
8686 } else {
8787 if ( word [ i ] === wordToMatchAgainst [ j ] ) {
88- let result : IMatch [ ] = null ;
88+ let result : IMatch [ ] | null = null ;
8989 if ( result = _matchesSubString ( word , wordToMatchAgainst , i + 1 , j + 1 ) ) {
9090 return join ( { start : j , end : j + 1 } , result ) ;
9191 }
@@ -144,15 +144,15 @@ function nextAnchor(camelCaseWord: string, start: number): number {
144144 return camelCaseWord . length ;
145145}
146146
147- function _matchesCamelCase ( word : string , camelCaseWord : string , i : number , j : number ) : IMatch [ ] {
147+ function _matchesCamelCase ( word : string , camelCaseWord : string , i : number , j : number ) : IMatch [ ] | null {
148148 if ( i === word . length ) {
149149 return [ ] ;
150150 } else if ( j === camelCaseWord . length ) {
151151 return null ;
152152 } else if ( word [ i ] !== camelCaseWord [ j ] . toLowerCase ( ) ) {
153153 return null ;
154154 } else {
155- let result : IMatch [ ] = null ;
155+ let result : IMatch [ ] | null = null ;
156156 let nextUpperIndex = j + 1 ;
157157 result = _matchesCamelCase ( word , camelCaseWord , i + 1 , j + 1 ) ;
158158 while ( ! result && ( nextUpperIndex = nextAnchor ( camelCaseWord , nextUpperIndex ) ) < camelCaseWord . length ) {
@@ -222,7 +222,7 @@ function isCamelCasePattern(word: string): boolean {
222222 }
223223}
224224
225- export function matchesCamelCase ( word : string , camelCaseWord : string ) : IMatch [ ] {
225+ export function matchesCamelCase ( word : string , camelCaseWord : string ) : IMatch [ ] | null {
226226 if ( ! camelCaseWord ) {
227227 return null ;
228228 }
@@ -251,7 +251,7 @@ export function matchesCamelCase(word: string, camelCaseWord: string): IMatch[]
251251 camelCaseWord = camelCaseWord . toLowerCase ( ) ;
252252 }
253253
254- let result : IMatch [ ] = null ;
254+ let result : IMatch [ ] | null = null ;
255255 let i = 0 ;
256256
257257 word = word . toLowerCase ( ) ;
@@ -267,12 +267,12 @@ export function matchesCamelCase(word: string, camelCaseWord: string): IMatch[]
267267// Otherwise also matches sub string of the word with beginnings of the words in the target. E.g. "gp" or "g p" will match "Git: Pull"
268268// Useful in cases where the target is words (e.g. command labels)
269269
270- export function matchesWords ( word : string , target : string , contiguous : boolean = false ) : IMatch [ ] {
270+ export function matchesWords ( word : string , target : string , contiguous : boolean = false ) : IMatch [ ] | null {
271271 if ( ! target || target . length === 0 ) {
272272 return null ;
273273 }
274274
275- let result : IMatch [ ] = null ;
275+ let result : IMatch [ ] | null = null ;
276276 let i = 0 ;
277277
278278 word = word . toLowerCase ( ) ;
@@ -284,15 +284,15 @@ export function matchesWords(word: string, target: string, contiguous: boolean =
284284 return result ;
285285}
286286
287- function _matchesWords ( word : string , target : string , i : number , j : number , contiguous : boolean ) : IMatch [ ] {
287+ function _matchesWords ( word : string , target : string , i : number , j : number , contiguous : boolean ) : IMatch [ ] | null {
288288 if ( i === word . length ) {
289289 return [ ] ;
290290 } else if ( j === target . length ) {
291291 return null ;
292292 } else if ( word [ i ] !== target [ j ] ) {
293293 return null ;
294294 } else {
295- let result : IMatch [ ] = null ;
295+ let result : IMatch [ ] | null = null ;
296296 let nextWordIndex = j + 1 ;
297297 result = _matchesWords ( word , target , i + 1 , j + 1 , contiguous ) ;
298298 if ( ! contiguous ) {
@@ -321,7 +321,7 @@ export const fuzzyContiguousFilter = or(matchesPrefix, matchesCamelCase, matches
321321const fuzzySeparateFilter = or ( matchesPrefix , matchesCamelCase , matchesSubString ) ;
322322const fuzzyRegExpCache = new LRUCache < string , RegExp > ( 10000 ) ; // bounded to 10000 elements
323323
324- export function matchesFuzzy ( word : string , wordToMatchAgainst : string , enableSeparateSubstringMatching = false ) : IMatch [ ] {
324+ export function matchesFuzzy ( word : string , wordToMatchAgainst : string , enableSeparateSubstringMatching = false ) : IMatch [ ] | null {
325325 if ( typeof word !== 'string' || typeof wordToMatchAgainst !== 'string' ) {
326326 return null ; // return early for invalid input
327327 }
@@ -334,7 +334,7 @@ export function matchesFuzzy(word: string, wordToMatchAgainst: string, enableSep
334334 }
335335
336336 // RegExp Filter
337- let match : RegExpExecArray = regexp . exec ( wordToMatchAgainst ) ;
337+ let match = regexp . exec ( wordToMatchAgainst ) ;
338338 if ( match ) {
339339 return [ { start : match . index , end : match . index + match [ 0 ] . length } ] ;
340340 }
@@ -372,7 +372,7 @@ export function createMatches(offsetOrScore: number[] | FuzzyScore): IMatch[] {
372372 } else {
373373 offsets = offsetOrScore as number [ ] ;
374374 }
375- let last : IMatch ;
375+ let last : IMatch | undefined ;
376376 for ( const pos of offsets ) {
377377 if ( last && last . end === pos ) {
378378 last . end += 1 ;
@@ -466,7 +466,7 @@ export interface FuzzyScorer {
466466 ( pattern : string , lowPattern : string , patternPos : number , word : string , lowWord : string , wordPos : number , firstMatchCanBeWeak : boolean ) : FuzzyScore ;
467467}
468468
469- export function fuzzyScore ( pattern : string , lowPattern : string , patternPos : number , word : string , lowWord : string , wordPos : number , firstMatchCanBeWeak : boolean ) : FuzzyScore {
469+ export function fuzzyScore ( pattern : string , lowPattern : string , patternPos : number , word : string , lowWord : string , wordPos : number , firstMatchCanBeWeak : boolean ) : FuzzyScore | undefined {
470470
471471 const patternLen = pattern . length > 100 ? 100 : pattern . length ;
472472 const wordLen = word . length > 100 ? 100 : word . length ;
@@ -711,16 +711,16 @@ class LazyArray {
711711
712712//#region --- graceful ---
713713
714- export function fuzzyScoreGracefulAggressive ( pattern : string , lowPattern : string , patternPos : number , word : string , lowWord : string , wordPos : number , firstMatchCanBeWeak : boolean ) : FuzzyScore {
714+ export function fuzzyScoreGracefulAggressive ( pattern : string , lowPattern : string , patternPos : number , word : string , lowWord : string , wordPos : number , firstMatchCanBeWeak : boolean ) : FuzzyScore | undefined {
715715 return fuzzyScoreWithPermutations ( pattern , lowPattern , patternPos , word , lowWord , wordPos , true , firstMatchCanBeWeak ) ;
716716}
717717
718- export function fuzzyScoreGraceful ( pattern : string , lowPattern : string , patternPos : number , word : string , lowWord : string , wordPos : number , firstMatchCanBeWeak : boolean ) : FuzzyScore {
718+ export function fuzzyScoreGraceful ( pattern : string , lowPattern : string , patternPos : number , word : string , lowWord : string , wordPos : number , firstMatchCanBeWeak : boolean ) : FuzzyScore | undefined {
719719 return fuzzyScoreWithPermutations ( pattern , lowPattern , patternPos , word , lowWord , wordPos , false , firstMatchCanBeWeak ) ;
720720}
721721
722- function fuzzyScoreWithPermutations ( pattern : string , lowPattern : string , patternPos : number , word : string , lowWord : string , wordPos : number , aggressive : boolean , firstMatchCanBeWeak : boolean ) : FuzzyScore {
723- let top : [ number , number [ ] ] = fuzzyScore ( pattern , lowPattern , patternPos , word , lowWord , wordPos , firstMatchCanBeWeak ) ;
722+ function fuzzyScoreWithPermutations ( pattern : string , lowPattern : string , patternPos : number , word : string , lowWord : string , wordPos : number , aggressive : boolean , firstMatchCanBeWeak : boolean ) : FuzzyScore | undefined {
723+ let top = fuzzyScore ( pattern , lowPattern , patternPos , word , lowWord , wordPos , firstMatchCanBeWeak ) ;
724724
725725 if ( top && ! aggressive ) {
726726 // when using the original pattern yield a result we`
@@ -752,7 +752,7 @@ function fuzzyScoreWithPermutations(pattern: string, lowPattern: string, pattern
752752 return top ;
753753}
754754
755- function nextTypoPermutation ( pattern : string , patternPos : number ) : string {
755+ function nextTypoPermutation ( pattern : string , patternPos : number ) : string | undefined {
756756
757757 if ( patternPos + 1 >= pattern . length ) {
758758 return undefined ;
0 commit comments