fix two issues with notebookType and document selectors, (1) make sure that notebookType: * matches only when a notebook is around, (2) include notebookType-property when converting from extHost type to renderer type, fyi @dbaeumer

This commit is contained in:
Johannes 2022-04-20 09:47:06 +02:00
parent 89d1004371
commit 5931aa8ed6
No known key found for this signature in database
GPG key ID: 6DEF802A22264FCA
4 changed files with 35 additions and 3 deletions

View file

@ -87,7 +87,7 @@ export function score(selector: LanguageSelector | undefined, candidateUri: URI,
if (notebookType) {
if (notebookType === candidateNotebookType) {
ret = 10;
} else if (notebookType === '*') {
} else if (notebookType === '*' && candidateNotebookType !== undefined) {
ret = Math.max(ret, 5);
} else {
return 0;

View file

@ -131,4 +131,23 @@ suite('LanguageSelector', function () {
let value = score(selector, URI.file('/home/user/Desktop/test.json'), 'json', true, undefined);
assert.strictEqual(value, 10);
});
test('NotebookType without notebook', function () {
let obj = {
uri: URI.parse('file:///my/file.bat'),
langId: 'bat',
};
let value = score({
language: 'bat',
notebookType: 'xxx'
}, obj.uri, obj.langId, true, undefined);
assert.strictEqual(value, 0);
value = score({
language: 'bat',
notebookType: '*'
}, obj.uri, obj.langId, true, undefined);
assert.strictEqual(value, 0);
});
});

View file

@ -1491,7 +1491,8 @@ export namespace LanguageSelector {
language: filter.language,
scheme: filter.scheme,
pattern: GlobPattern.from(filter.pattern),
exclusive: filter.exclusive
exclusive: filter.exclusive,
notebookType: filter.notebookType
};
}
}

View file

@ -6,7 +6,7 @@
import * as assert from 'assert';
import * as extHostTypes from 'vs/workbench/api/common/extHostTypes';
import { MarkdownString, NotebookCellOutputItem, NotebookData } from 'vs/workbench/api/common/extHostTypeConverters';
import { MarkdownString, NotebookCellOutputItem, NotebookData, LanguageSelector } from 'vs/workbench/api/common/extHostTypeConverters';
import { isEmptyObject } from 'vs/base/common/types';
import { forEach } from 'vs/base/common/collections';
import { LogLevel as _MainLogLevel } from 'vs/platform/log/common/log';
@ -111,4 +111,16 @@ suite('ExtHostTypeConverter', function () {
assert.strictEqual(item2.mime, item.mime);
assert.deepStrictEqual(Array.from(item2.data), Array.from(item.data));
});
test('LanguageSelector', function () {
const out = LanguageSelector.from({ language: 'bat', notebookType: 'xxx' });
assert.ok(typeof out === 'object');
assert.deepStrictEqual(out, {
language: 'bat',
notebookType: 'xxx',
scheme: undefined,
pattern: undefined,
exclusive: undefined,
});
});
});