提交 27a2bfef 编写于 作者: B Benjamin Pasero

more tests (for #35572)

上级 6779069b
......@@ -421,7 +421,7 @@ function printTable(table: number[][], pattern: string, patternLen: number, word
return ret;
}
export function isSeparatorAtPos(value: string, index: number): boolean {
function isSeparatorAtPos(value: string, index: number): boolean {
if (index < 0 || index >= value.length) {
return false;
}
......
......@@ -6,10 +6,11 @@
'use strict';
import { compareAnything } from 'vs/base/common/comparers';
import { matchesPrefix, IMatch, createMatches, matchesCamelCase, isSeparatorAtPos, isUpper } from 'vs/base/common/filters';
import { matchesPrefix, IMatch, createMatches, matchesCamelCase, isUpper } from 'vs/base/common/filters';
import { isEqual, nativeSep } from 'vs/base/common/paths';
import { isWindows } from 'vs/base/common/platform';
import { stripWildcards } from 'vs/base/common/strings';
import { CharCode } from 'vs/base/common/charCode';
export type Score = [number /* score */, number[] /* match positions */];
export type ScorerCache = { [key: string]: IItemScore };
......@@ -189,22 +190,26 @@ function computeCharScore(query: string, queryLower: string, queryIndex: number,
// }
}
// After separator bonus
else if (isSeparatorAtPos(target, targetIndex - 1)) {
score += 4;
else {
// if (DEBUG) {
// console.log('After separtor bonus: +4');
// }
}
// After separator bonus
const separatorBonus = scoreSeparatorAtPos(target.charCodeAt(targetIndex - 1));
if (separatorBonus) {
score += separatorBonus;
// Inside word upper case bonus
else if (isUpper(target.charCodeAt(targetIndex))) {
score += 1;
// if (DEBUG) {
// console.log('After separtor bonus: +4');
// }
}
// if (DEBUG) {
// console.log('Inside word upper case bonus: +1');
// }
// Inside word upper case bonus (camel case)
else if (isUpper(target.charCodeAt(targetIndex))) {
score += 1;
// if (DEBUG) {
// console.log('Inside word upper case bonus: +1');
// }
}
}
// if (DEBUG) {
......@@ -214,6 +219,24 @@ function computeCharScore(query: string, queryLower: string, queryIndex: number,
return score;
}
function scoreSeparatorAtPos(charCode: number): number {
switch (charCode) {
case CharCode.Slash:
case CharCode.Backslash:
return 5; // prefer path separators...
case CharCode.Underline:
case CharCode.Dash:
case CharCode.Period:
case CharCode.Space:
case CharCode.SingleQuote:
case CharCode.DoubleQuote:
case CharCode.Colon:
return 4; // ...over other separators
default:
return 0;
}
}
// function printMatrix(query: string, target: string, matches: number[], scores: number[]): void {
// console.log('\t' + target.split('').join('\t'));
// for (let queryIndex = 0; queryIndex < query.length; queryIndex++) {
......
......@@ -715,6 +715,19 @@ suite('Quick Open Scorer', () => {
assert.equal(res[0], resourceB);
});
test('compareFilesByScore - avoid match scattering (bug #35572)', function () {
const resourceA = URI.file('static/app/source/angluar/-admin/-organization/-settings/layout/layout.js');
const resourceB = URI.file('static/app/source/angular/-admin/-project/-settings/_settings/settings.js');
let query = 'partisettings';
let res = [resourceA, resourceB].sort((r1, r2) => compareItemsByScore(r1, r2, query, true, ResourceAccessor, cache));
assert.equal(res[0], resourceB);
res = [resourceB, resourceA].sort((r1, r2) => compareItemsByScore(r1, r2, query, true, ResourceAccessor, cache));
assert.equal(res[0], resourceB);
});
test('compareFilesByScore - prefer shorter hit (bug #20546)', function () {
const resourceA = URI.file('editor/core/components/tests/list-view-spec.js');
const resourceB = URI.file('editor/core/components/list-view.js');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册