提交 0b30dbfc 编写于 作者: J Johannes Rieken

change LanguageFilter matching rule to be the max not the sum of each match, fixes #7031

上级 9b33a963
......@@ -37,15 +37,19 @@ export function score(selector: LanguageSelector, uri: URI, language: string): n
return 0;
}
} else if (selector) {
let filter = <LanguageFilter>selector;
let value = 0;
// all must match but only highest score counts
const filter = <LanguageFilter>selector;
let valueLanguage = 0;
let valueScheme = 0;
let valuePattern = 0;
// language id
if (filter.language) {
if (filter.language === language) {
value += 10;
valueLanguage = 10;
} else if (filter.language === '*') {
value += 5;
valueLanguage = 5;
} else {
return 0;
}
......@@ -54,7 +58,7 @@ export function score(selector: LanguageSelector, uri: URI, language: string): n
// scheme
if (filter.scheme) {
if (filter.scheme === uri.scheme) {
value += 10;
valueScheme = 10;
} else {
return 0;
}
......@@ -63,14 +67,14 @@ export function score(selector: LanguageSelector, uri: URI, language: string): n
// match fsPath with pattern
if (filter.pattern) {
if (filter.pattern === uri.fsPath) {
value += 10;
valuePattern = 10;
} else if (matchGlobPattern(filter.pattern, uri.fsPath)) {
value += 5;
valuePattern = 5;
} else {
return 0;
}
}
return value;
return Math.max(valueLanguage, valueScheme, valuePattern);
}
}
......@@ -31,7 +31,7 @@ suite('LanguageSelector', function() {
test('score, filter', function() {
assert.equal(score('farboo', model.uri, model.language), 10);
assert.equal(score({ language: 'farboo'}, model.uri, model.language), 10);
assert.equal(score({ language: 'farboo', scheme: 'file' }, model.uri, model.language), 20);
assert.equal(score({ language: 'farboo', scheme: 'file' }, model.uri, model.language), 10);
assert.equal(score({ language: 'farboo', scheme: 'http' }, model.uri, model.language), 0);
assert.equal(score({ pattern: '**/*.fb' }, model.uri, model.language), 5);
......@@ -42,9 +42,9 @@ suite('LanguageSelector', function() {
let match = { language: 'farboo', scheme: 'file' };
let fail = { language: 'farboo', scheme: 'http' };
assert.equal(score(match, model.uri, model.language), 20);
assert.equal(score(match, model.uri, model.language), 10);
assert.equal(score(fail, model.uri, model.language), 0);
assert.equal(score([match, fail], model.uri, model.language), 20);
assert.equal(score([match, fail], model.uri, model.language), 10);
assert.equal(score(['farboo', '*'], model.uri, model.language), 10);
assert.equal(score(['*', 'farboo'], model.uri, model.language), 10);
});
......
......@@ -3543,12 +3543,12 @@ declare namespace vscode {
* (2.1) When both are equal score is `10`,
* (2.2) When the selector is `*` score is `5`,
* (2.3) Else score is `0`.
* (3) When selector is a [filter](#DocumentFilter) every property must score higher `0`. Iff the score is the sum of the following:
* (3) When selector is a [filter](#DocumentFilter) return the maximum individual score given that each score is `>0`.
* (3.1) When [language](#DocumentFilter.language) is set apply rules from #2, when `0` the total score is `0`.
* (3.2) When [scheme](#Document.scheme) is set and equals the [uri](#TextDocument.uri)-scheme add `10` to the score, else the total score is `0`.
* (3.2) When [scheme](#Document.scheme) is set and equals the [uri](#TextDocument.uri)-scheme score with `10`, else the total score is `0`.
* (3.3) When [pattern](#Document.pattern) is set
* (3.3.1) pattern eqauls the [uri](#TextDocument.uri)-fsPath add `10` to the score,
* (3.3.1) if the pattern matches as glob-pattern add `5` to the score,
* (3.3.1) pattern equals the [uri](#TextDocument.uri)-fsPath score with `10`,
* (3.3.1) if the pattern matches as glob-pattern score with `5`,
* (3.3.1) the total score is `0`
* ```
*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册