Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/microsoft/vscode.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/vs/base/common/filters.ts')
-rw-r--r--src/vs/base/common/filters.ts41
1 files changed, 28 insertions, 13 deletions
diff --git a/src/vs/base/common/filters.ts b/src/vs/base/common/filters.ts
index e1d674ff9a3..d0a8a09aa70 100644
--- a/src/vs/base/common/filters.ts
+++ b/src/vs/base/common/filters.ts
@@ -363,14 +363,14 @@ export function matchesFuzzy(word: string, wordToMatchAgainst: string, enableSep
* powerful than `matchesFuzzy`
*/
export function matchesFuzzy2(pattern: string, word: string): IMatch[] | null {
- const score = fuzzyScore(pattern, pattern.toLowerCase(), 0, word, word.toLowerCase(), 0, true);
+ const score = fuzzyScore(pattern, pattern.toLowerCase(), 0, word, word.toLowerCase(), 0, { firstMatchCanBeWeak: true, boostFullMatch: true });
return score ? createMatches(score) : null;
}
export function anyScore(pattern: string, lowPattern: string, patternPos: number, word: string, lowWord: string, wordPos: number): FuzzyScore {
const max = Math.min(13, pattern.length);
for (; patternPos < max; patternPos++) {
- const result = fuzzyScore(pattern, lowPattern, patternPos, word, lowWord, wordPos, false);
+ const result = fuzzyScore(pattern, lowPattern, patternPos, word, lowWord, wordPos, { firstMatchCanBeWeak: false, boostFullMatch: true });
if (result) {
return result;
}
@@ -472,8 +472,13 @@ function isSeparatorAtPos(value: string, index: number): boolean {
case CharCode.Colon:
case CharCode.DollarSign:
case CharCode.LessThan:
+ case CharCode.GreaterThan:
case CharCode.OpenParen:
+ case CharCode.CloseParen:
case CharCode.OpenSquareBracket:
+ case CharCode.CloseSquareBracket:
+ case CharCode.OpenCurlyBrace:
+ case CharCode.CloseCurlyBrace:
return true;
case undefined:
return false;
@@ -541,11 +546,21 @@ export namespace FuzzyScore {
}
}
+export abstract class FuzzyScoreOptions {
+
+ static default = { boostFullMatch: true, firstMatchCanBeWeak: false };
+
+ constructor(
+ readonly firstMatchCanBeWeak: boolean,
+ readonly boostFullMatch: boolean,
+ ) { }
+}
+
export interface FuzzyScorer {
- (pattern: string, lowPattern: string, patternPos: number, word: string, lowWord: string, wordPos: number, firstMatchCanBeWeak: boolean): FuzzyScore | undefined;
+ (pattern: string, lowPattern: string, patternPos: number, word: string, lowWord: string, wordPos: number, options?: FuzzyScoreOptions): FuzzyScore | undefined;
}
-export function fuzzyScore(pattern: string, patternLow: string, patternStart: number, word: string, wordLow: string, wordStart: number, firstMatchCanBeWeak: boolean): FuzzyScore | undefined {
+export function fuzzyScore(pattern: string, patternLow: string, patternStart: number, word: string, wordLow: string, wordStart: number, options: FuzzyScoreOptions = FuzzyScoreOptions.default): FuzzyScore | undefined {
const patternLen = pattern.length > _maxLen ? _maxLen : pattern.length;
const wordLen = word.length > _maxLen ? _maxLen : word.length;
@@ -630,7 +645,7 @@ export function fuzzyScore(pattern: string, patternLow: string, patternStart: nu
printTables(pattern, patternStart, word, wordStart);
}
- if (!hasStrongFirstMatch[0] && !firstMatchCanBeWeak) {
+ if (!hasStrongFirstMatch[0] && !options.firstMatchCanBeWeak) {
return undefined;
}
@@ -684,7 +699,7 @@ export function fuzzyScore(pattern: string, patternLow: string, patternStart: nu
result.push(column);
}
- if (wordLen === patternLen) {
+ if (wordLen === patternLen && options.boostFullMatch) {
// the word matches the pattern with all characters!
// giving the score a total match boost (to come up ahead other words)
result[0] += 2;
@@ -783,16 +798,16 @@ function _doScore(
//#region --- graceful ---
-export function fuzzyScoreGracefulAggressive(pattern: string, lowPattern: string, patternPos: number, word: string, lowWord: string, wordPos: number, firstMatchCanBeWeak: boolean): FuzzyScore | undefined {
- return fuzzyScoreWithPermutations(pattern, lowPattern, patternPos, word, lowWord, wordPos, true, firstMatchCanBeWeak);
+export function fuzzyScoreGracefulAggressive(pattern: string, lowPattern: string, patternPos: number, word: string, lowWord: string, wordPos: number, options?: FuzzyScoreOptions): FuzzyScore | undefined {
+ return fuzzyScoreWithPermutations(pattern, lowPattern, patternPos, word, lowWord, wordPos, true, options);
}
-export function fuzzyScoreGraceful(pattern: string, lowPattern: string, patternPos: number, word: string, lowWord: string, wordPos: number, firstMatchCanBeWeak: boolean): FuzzyScore | undefined {
- return fuzzyScoreWithPermutations(pattern, lowPattern, patternPos, word, lowWord, wordPos, false, firstMatchCanBeWeak);
+export function fuzzyScoreGraceful(pattern: string, lowPattern: string, patternPos: number, word: string, lowWord: string, wordPos: number, options?: FuzzyScoreOptions): FuzzyScore | undefined {
+ return fuzzyScoreWithPermutations(pattern, lowPattern, patternPos, word, lowWord, wordPos, false, options);
}
-function fuzzyScoreWithPermutations(pattern: string, lowPattern: string, patternPos: number, word: string, lowWord: string, wordPos: number, aggressive: boolean, firstMatchCanBeWeak: boolean): FuzzyScore | undefined {
- let top = fuzzyScore(pattern, lowPattern, patternPos, word, lowWord, wordPos, firstMatchCanBeWeak);
+function fuzzyScoreWithPermutations(pattern: string, lowPattern: string, patternPos: number, word: string, lowWord: string, wordPos: number, aggressive: boolean, options?: FuzzyScoreOptions): FuzzyScore | undefined {
+ let top = fuzzyScore(pattern, lowPattern, patternPos, word, lowWord, wordPos, options);
if (top && !aggressive) {
// when using the original pattern yield a result we`
@@ -810,7 +825,7 @@ function fuzzyScoreWithPermutations(pattern: string, lowPattern: string, pattern
for (let movingPatternPos = patternPos + 1; movingPatternPos < tries; movingPatternPos++) {
const newPattern = nextTypoPermutation(pattern, movingPatternPos);
if (newPattern) {
- const candidate = fuzzyScore(newPattern, newPattern.toLowerCase(), patternPos, word, lowWord, wordPos, firstMatchCanBeWeak);
+ const candidate = fuzzyScore(newPattern, newPattern.toLowerCase(), patternPos, word, lowWord, wordPos, options);
if (candidate) {
candidate[0] -= 3; // permutation penalty
if (!top || candidate[0] > top[0]) {