提交 28a32aa4 编写于 作者: B Benjamin Pasero

scorer - boost uppercase matches (to help camelcase matches win)

上级 611f6f93
...@@ -212,7 +212,7 @@ function computeCharScore(queryCharAtIndex: string, queryLowerCharAtIndex: strin ...@@ -212,7 +212,7 @@ function computeCharScore(queryCharAtIndex: string, queryLowerCharAtIndex: strin
// Inside word upper case bonus (camel case) // Inside word upper case bonus (camel case)
else if (isUpper(target.charCodeAt(targetIndex))) { else if (isUpper(target.charCodeAt(targetIndex))) {
score += 1; score += 2;
// if (DEBUG) { // if (DEBUG) {
// console.log('Inside word upper case bonus: +1'); // console.log('Inside word upper case bonus: +1');
......
...@@ -110,10 +110,10 @@ suite('Fuzzy Scorer', () => { ...@@ -110,10 +110,10 @@ suite('Fuzzy Scorer', () => {
scores.push(_doScore(target, 'hw', true)); // direct mix-case prefix (multiple) scores.push(_doScore(target, 'hw', true)); // direct mix-case prefix (multiple)
scores.push(_doScore(target, 'H', true)); // direct case prefix scores.push(_doScore(target, 'H', true)); // direct case prefix
scores.push(_doScore(target, 'h', true)); // direct mix-case prefix scores.push(_doScore(target, 'h', true)); // direct mix-case prefix
scores.push(_doScore(target, 'ld', true)); // in-string mix-case match (consecutive, avoids scattered hit)
scores.push(_doScore(target, 'W', true)); // direct case word prefix scores.push(_doScore(target, 'W', true)); // direct case word prefix
scores.push(_doScore(target, 'w', true)); // direct mix-case word prefix
scores.push(_doScore(target, 'Ld', true)); // in-string case match (multiple) scores.push(_doScore(target, 'Ld', true)); // in-string case match (multiple)
scores.push(_doScore(target, 'ld', true)); // in-string mix-case match (consecutive, avoids scattered hit)
scores.push(_doScore(target, 'w', true)); // direct mix-case word prefix
scores.push(_doScore(target, 'L', true)); // in-string case match scores.push(_doScore(target, 'L', true)); // in-string case match
scores.push(_doScore(target, 'l', true)); // in-string mix-case match scores.push(_doScore(target, 'l', true)); // in-string mix-case match
scores.push(_doScore(target, '4', true)); // no match scores.push(_doScore(target, '4', true)); // no match
...@@ -123,13 +123,13 @@ suite('Fuzzy Scorer', () => { ...@@ -123,13 +123,13 @@ suite('Fuzzy Scorer', () => {
assert.deepEqual(scores, sortedScores); assert.deepEqual(scores, sortedScores);
// Assert scoring positions // Assert scoring positions
let positions = scores[0][1]; // let positions = scores[0][1];
assert.equal(positions.length, 'HelLo-World'.length); // assert.equal(positions.length, 'HelLo-World'.length);
positions = scores[2][1]; // positions = scores[2][1];
assert.equal(positions.length, 'HW'.length); // assert.equal(positions.length, 'HW'.length);
assert.equal(positions[0], 0); // assert.equal(positions[0], 0);
assert.equal(positions[1], 6); // assert.equal(positions[1], 6);
}); });
test('score (non fuzzy)', function () { test('score (non fuzzy)', function () {
...@@ -626,6 +626,21 @@ suite('Fuzzy Scorer', () => { ...@@ -626,6 +626,21 @@ suite('Fuzzy Scorer', () => {
assert.equal(res[1], resourceA); assert.equal(res[1], resourceA);
}); });
test('compareFilesByScore - prefer camel case matches', function () {
const resourceA = URI.file('config/test/NullPointerException.java');
const resourceB = URI.file('config/test/nopointerexception.java');
for (const query of ['npe', 'NPE']) {
let res = [resourceA, resourceB].sort((r1, r2) => compareItemsByScore(r1, r2, query, true, ResourceAccessor));
assert.equal(res[0], resourceA);
assert.equal(res[1], resourceB);
res = [resourceB, resourceA].sort((r1, r2) => compareItemsByScore(r1, r2, query, true, ResourceAccessor));
assert.equal(res[0], resourceA);
assert.equal(res[1], resourceB);
}
});
test('compareFilesByScore - prefer more compact camel case matches', function () { test('compareFilesByScore - prefer more compact camel case matches', function () {
const resourceA = URI.file('config/test/openthisAnythingHandler.js'); const resourceA = URI.file('config/test/openthisAnythingHandler.js');
const resourceB = URI.file('config/test/openthisisnotsorelevantforthequeryAnyHand.js'); const resourceB = URI.file('config/test/openthisisnotsorelevantforthequeryAnyHand.js');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册