Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero authored and leilapearson committed Apr 27, 2020
1 parent 2025795 commit 550fc69
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/vs/base/common/filters.ts
Expand Up @@ -392,7 +392,7 @@ export function anyScore(pattern: string, lowPattern: string, _patternPos: numbe

//#region --- fuzzyScore ---

export function createMatches(score: undefined | FuzzyScore, offset = 0): IMatch[] {
export function createMatches(score: undefined | FuzzyScore): IMatch[] {
if (typeof score === 'undefined') {
return [];
}
Expand All @@ -404,10 +404,10 @@ export function createMatches(score: undefined | FuzzyScore, offset = 0): IMatch
for (let pos = wordStart; pos < _maxLen; pos++) {
if (matches[matches.length - (pos + 1)] === '1') {
const last = res[res.length - 1];
if (last && last.end === pos + offset) {
last.end = pos + offset + 1;
if (last && last.end === pos) {
last.end = pos + 1;
} else {
res.push({ start: pos + offset, end: pos + offset + 1 });
res.push({ start: pos, end: pos + 1 });
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/vs/base/common/fuzzyScorer.ts
Expand Up @@ -281,24 +281,24 @@ export type FuzzyScore2 = [number | undefined /* score */, IMatch[]];

const NO_SCORE2: FuzzyScore2 = [undefined, []];

export function scoreFuzzy2(target: string, query: IPreparedQuery | IPreparedQueryPiece, patternStart = 0, matchOffset = 0): FuzzyScore2 {
export function scoreFuzzy2(target: string, query: IPreparedQuery | IPreparedQueryPiece, patternStart = 0, wordStart = 0): FuzzyScore2 {

// Score: multiple inputs
const preparedQuery = query as IPreparedQuery;
if (preparedQuery.values && preparedQuery.values.length > 1) {
return doScoreFuzzy2Multiple(target, preparedQuery.values, patternStart, matchOffset);
return doScoreFuzzy2Multiple(target, preparedQuery.values, patternStart, wordStart);
}

// Score: single input
return doScoreFuzzy2Single(target, query, patternStart, matchOffset);
return doScoreFuzzy2Single(target, query, patternStart, wordStart);
}

function doScoreFuzzy2Multiple(target: string, query: IPreparedQueryPiece[], patternStart: number, matchOffset: number): FuzzyScore2 {
function doScoreFuzzy2Multiple(target: string, query: IPreparedQueryPiece[], patternStart: number, wordStart: number): FuzzyScore2 {
let totalScore = 0;
const totalMatches: IMatch[] = [];

for (const queryPiece of query) {
const [score, matches] = doScoreFuzzy2Single(target, queryPiece, patternStart, matchOffset);
const [score, matches] = doScoreFuzzy2Single(target, queryPiece, patternStart, wordStart);
if (typeof score !== 'number') {
// if a single query value does not match, return with
// no score entirely, we require all queries to match
Expand All @@ -314,13 +314,13 @@ function doScoreFuzzy2Multiple(target: string, query: IPreparedQueryPiece[], pat
return [totalScore, normalizeMatches(totalMatches)];
}

function doScoreFuzzy2Single(target: string, query: IPreparedQueryPiece, patternStart: number, matchOffset: number): FuzzyScore2 {
const score = fuzzyScore(query.original, query.originalLowercase, patternStart, target, target.toLowerCase(), 0, true);
function doScoreFuzzy2Single(target: string, query: IPreparedQueryPiece, patternStart: number, wordStart: number): FuzzyScore2 {
const score = fuzzyScore(query.original, query.originalLowercase, patternStart, target, target.toLowerCase(), wordStart, true);
if (!score) {
return NO_SCORE2;
}

return [score[0], createFuzzyMatches(score, matchOffset)];
return [score[0], createFuzzyMatches(score)];
}

//#endregion
Expand Down
4 changes: 2 additions & 2 deletions src/vs/base/test/common/fuzzyScorer.test.ts
Expand Up @@ -990,14 +990,14 @@ suite('Fuzzy Scorer', () => {
const target = 'HeLlo-World';

for (const offset of [0, 3]) {
let [score, matches] = _doScore2(target, 'HeLlo-World', offset);
let [score, matches] = _doScore2(offset === 0 ? target : `123${target}`, 'HeLlo-World', offset);

assert.ok(score);
assert.equal(matches.length, 1);
assert.equal(matches[0].start, 0 + offset);
assert.equal(matches[0].end, target.length + offset);

[score, matches] = _doScore2(target, 'HW', offset);
[score, matches] = _doScore2(offset === 0 ? target : `123${target}`, 'HW', offset);

assert.ok(score);
assert.equal(matches.length, 2);
Expand Down
4 changes: 2 additions & 2 deletions src/vs/editor/contrib/quickAccess/gotoSymbolQuickAccess.ts
Expand Up @@ -257,15 +257,15 @@ export abstract class AbstractGotoSymbolQuickAccessProvider extends AbstractEdit
// case we want to skip the container query altogether.
let skipContainerQuery = false;
if (symbolQuery !== query) {
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabel, { ...query, values: undefined /* disable multi-query support */ }, filterPos, symbolLabelIconOffset);
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabelWithIcon, { ...query, values: undefined /* disable multi-query support */ }, filterPos, symbolLabelIconOffset);
if (typeof symbolScore === 'number') {
skipContainerQuery = true; // since we consumed the query, skip any container matching
}
}

// Otherwise: score on the symbol query and match on the container later
if (typeof symbolScore !== 'number') {
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabel, symbolQuery, filterPos, symbolLabelIconOffset);
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabelWithIcon, symbolQuery, filterPos, symbolLabelIconOffset);
if (typeof symbolScore !== 'number') {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/contrib/search/browser/symbolsQuickAccess.ts
Expand Up @@ -144,15 +144,15 @@ export class SymbolsQuickAccessProvider extends PickerQuickAccessProvider<ISymbo
// can be a match on a markdown symbol "change log"). In that
// case we want to skip the container query altogether.
if (symbolQuery !== query) {
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabel, { ...query, values: undefined /* disable multi-query support */ }, 0, symbolLabelIconOffset);
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabelWithIcon, { ...query, values: undefined /* disable multi-query support */ }, 0, symbolLabelIconOffset);
if (typeof symbolScore === 'number') {
skipContainerQuery = true; // since we consumed the query, skip any container matching
}
}

// Otherwise: score on the symbol query and match on the container later
if (typeof symbolScore !== 'number') {
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabel, symbolQuery, 0, symbolLabelIconOffset);
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabelWithIcon, symbolQuery, 0, symbolLabelIconOffset);
if (typeof symbolScore !== 'number') {
continue;
}
Expand Down

0 comments on commit 550fc69

Please sign in to comment.