Merge from vscode a348d103d1256a06a2c9b3f9b406298a9fef6898 (#15681)

* Merge from vscode a348d103d1256a06a2c9b3f9b406298a9fef6898

* Fixes and cleanup

* Distro

* Fix hygiene yarn

* delete no yarn lock changes file

* Fix hygiene

* Fix layer check

* Fix CI

* Skip lib checks

* Remove tests deleted in vs code

* Fix tests

* Distro

* Fix tests and add removed extension point

* Skip failing notebook tests for now

* Disable broken tests and cleanup build folder

* Update yarn.lock and fix smoke tests

* Bump sqlite

* fix contributed actions and file spacing

* Fix user data path

* Update yarn.locks

Co-authored-by: ADS Merger <karlb@microsoft.com>
This commit is contained in:
Charles Gagnon
2021-06-17 08:17:11 -07:00
committed by GitHub
parent fdcb97c7f7
commit 3cb2f552a6
2582 changed files with 124827 additions and 87099 deletions

View File

@@ -11,11 +11,11 @@ import { isWindows } from 'vs/base/common/platform';
suite('ExtHost API', function () {
test('issue #51387: originalFSPath', function () {
if (isWindows) {
assert.equal(originalFSPath(URI.file('C:\\test')).charAt(0), 'C');
assert.equal(originalFSPath(URI.file('c:\\test')).charAt(0), 'c');
assert.strictEqual(originalFSPath(URI.file('C:\\test')).charAt(0), 'C');
assert.strictEqual(originalFSPath(URI.file('c:\\test')).charAt(0), 'c');
assert.equal(originalFSPath(URI.revive(JSON.parse(JSON.stringify(URI.file('C:\\test'))))).charAt(0), 'C');
assert.equal(originalFSPath(URI.revive(JSON.parse(JSON.stringify(URI.file('c:\\test'))))).charAt(0), 'c');
assert.strictEqual(originalFSPath(URI.revive(JSON.parse(JSON.stringify(URI.file('C:\\test'))))).charAt(0), 'C');
assert.strictEqual(originalFSPath(URI.revive(JSON.parse(JSON.stringify(URI.file('c:\\test'))))).charAt(0), 'c');
}
});
});

View File

@@ -90,14 +90,14 @@ suite('ExtHostLanguageFeatureCommands', function () {
rpcProtocol = new TestRPCProtocol();
const services = new ServiceCollection();
services.set(IExtensionService, new class extends mock<IExtensionService>() {
async activateByEvent() {
override async activateByEvent() {
}
});
services.set(ICommandService, new SyncDescriptor(class extends mock<ICommandService>() {
executeCommand(id: string, ...args: any): any {
override executeCommand(id: string, ...args: any): any {
const command = CommandsRegistry.getCommands().get(id);
if (!command) {
return Promise.reject(new Error(id + ' NOT known'));
@@ -108,17 +108,17 @@ suite('ExtHostLanguageFeatureCommands', function () {
}));
services.set(IMarkerService, new MarkerService());
services.set(IModelService, new class extends mock<IModelService>() {
getModel() { return model; }
override getModel() { return model; }
});
services.set(ITextModelService, new class extends mock<ITextModelService>() {
async createModelReference() {
override async createModelReference() {
return new ImmortalReference<IResolvedTextEditorModel>(new class extends mock<IResolvedTextEditorModel>() {
textEditorModel = model;
override textEditorModel = model;
});
}
});
services.set(IEditorWorkerService, new class extends mock<IEditorWorkerService>() {
async computeMoreMinimalEdits(_uri: any, edits: any) {
override async computeMoreMinimalEdits(_uri: any, edits: any) {
return edits || undefined;
}
});
@@ -280,15 +280,21 @@ suite('ExtHostLanguageFeatureCommands', function () {
disposables.push(extHost.registerDefinitionProvider(nullExtensionDescription, defaultSelector, <vscode.DefinitionProvider>{
provideDefinition(doc: any): any {
return new types.Location(doc.uri, new types.Range(0, 0, 0, 0));
return new types.Location(doc.uri, new types.Range(1, 0, 0, 0));
}
}));
disposables.push(extHost.registerDefinitionProvider(nullExtensionDescription, defaultSelector, <vscode.DefinitionProvider>{
provideDefinition(doc: any): any {
// duplicate result will get removed
return new types.Location(doc.uri, new types.Range(1, 0, 0, 0));
}
}));
disposables.push(extHost.registerDefinitionProvider(nullExtensionDescription, defaultSelector, <vscode.DefinitionProvider>{
provideDefinition(doc: any): any {
return [
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
new types.Location(doc.uri, new types.Range(2, 0, 0, 0)),
new types.Location(doc.uri, new types.Range(3, 0, 0, 0)),
new types.Location(doc.uri, new types.Range(4, 0, 0, 0)),
];
}
}));
@@ -304,12 +310,48 @@ suite('ExtHostLanguageFeatureCommands', function () {
});
});
test('Definition, back and forth (sorting & de-deduping)', function () {
disposables.push(extHost.registerDefinitionProvider(nullExtensionDescription, defaultSelector, <vscode.DefinitionProvider>{
provideDefinition(doc: any): any {
return new types.Location(URI.parse('file:///b'), new types.Range(1, 0, 0, 0));
}
}));
disposables.push(extHost.registerDefinitionProvider(nullExtensionDescription, defaultSelector, <vscode.DefinitionProvider>{
provideDefinition(doc: any): any {
// duplicate result will get removed
return new types.Location(URI.parse('file:///b'), new types.Range(1, 0, 0, 0));
}
}));
disposables.push(extHost.registerDefinitionProvider(nullExtensionDescription, defaultSelector, <vscode.DefinitionProvider>{
provideDefinition(doc: any): any {
return [
new types.Location(URI.parse('file:///a'), new types.Range(2, 0, 0, 0)),
new types.Location(URI.parse('file:///c'), new types.Range(3, 0, 0, 0)),
new types.Location(URI.parse('file:///d'), new types.Range(4, 0, 0, 0)),
];
}
}));
return rpcProtocol.sync().then(() => {
return commands.executeCommand<vscode.Location[]>('vscode.executeDefinitionProvider', model.uri, new types.Position(0, 0)).then(values => {
assert.strictEqual(values.length, 4);
assert.strictEqual(values[0].uri.path, '/a');
assert.strictEqual(values[1].uri.path, '/b');
assert.strictEqual(values[2].uri.path, '/c');
assert.strictEqual(values[3].uri.path, '/d');
});
});
});
test('Definition Link', () => {
disposables.push(extHost.registerDefinitionProvider(nullExtensionDescription, defaultSelector, <vscode.DefinitionProvider>{
provideDefinition(doc: any): (vscode.Location | vscode.LocationLink)[] {
return [
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
{ targetUri: doc.uri, targetRange: new types.Range(0, 0, 0, 0), targetSelectionRange: new types.Range(1, 1, 1, 1), originSelectionRange: new types.Range(2, 2, 2, 2) }
{ targetUri: doc.uri, targetRange: new types.Range(1, 0, 0, 0), targetSelectionRange: new types.Range(1, 1, 1, 1), originSelectionRange: new types.Range(2, 2, 2, 2) }
];
}
}));
@@ -338,15 +380,21 @@ suite('ExtHostLanguageFeatureCommands', function () {
disposables.push(extHost.registerDeclarationProvider(nullExtensionDescription, defaultSelector, <vscode.DeclarationProvider>{
provideDeclaration(doc: any): any {
return new types.Location(doc.uri, new types.Range(0, 0, 0, 0));
return new types.Location(doc.uri, new types.Range(1, 0, 0, 0));
}
}));
disposables.push(extHost.registerDeclarationProvider(nullExtensionDescription, defaultSelector, <vscode.DeclarationProvider>{
provideDeclaration(doc: any): any {
// duplicate result will get removed
return new types.Location(doc.uri, new types.Range(1, 0, 0, 0));
}
}));
disposables.push(extHost.registerDeclarationProvider(nullExtensionDescription, defaultSelector, <vscode.DeclarationProvider>{
provideDeclaration(doc: any): any {
return [
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
new types.Location(doc.uri, new types.Range(2, 0, 0, 0)),
new types.Location(doc.uri, new types.Range(3, 0, 0, 0)),
new types.Location(doc.uri, new types.Range(4, 0, 0, 0)),
];
}
}));
@@ -367,7 +415,7 @@ suite('ExtHostLanguageFeatureCommands', function () {
provideDeclaration(doc: any): (vscode.Location | vscode.LocationLink)[] {
return [
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
{ targetUri: doc.uri, targetRange: new types.Range(0, 0, 0, 0), targetSelectionRange: new types.Range(1, 1, 1, 1), originSelectionRange: new types.Range(2, 2, 2, 2) }
{ targetUri: doc.uri, targetRange: new types.Range(1, 0, 0, 0), targetSelectionRange: new types.Range(1, 1, 1, 1), originSelectionRange: new types.Range(2, 2, 2, 2) }
];
}
}));
@@ -407,15 +455,21 @@ suite('ExtHostLanguageFeatureCommands', function () {
disposables.push(extHost.registerTypeDefinitionProvider(nullExtensionDescription, defaultSelector, <vscode.TypeDefinitionProvider>{
provideTypeDefinition(doc: any): any {
return new types.Location(doc.uri, new types.Range(0, 0, 0, 0));
return new types.Location(doc.uri, new types.Range(1, 0, 0, 0));
}
}));
disposables.push(extHost.registerTypeDefinitionProvider(nullExtensionDescription, defaultSelector, <vscode.TypeDefinitionProvider>{
provideTypeDefinition(doc: any): any {
// duplicate result will get removed
return new types.Location(doc.uri, new types.Range(1, 0, 0, 0));
}
}));
disposables.push(extHost.registerTypeDefinitionProvider(nullExtensionDescription, defaultSelector, <vscode.TypeDefinitionProvider>{
provideTypeDefinition(doc: any): any {
return [
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
new types.Location(doc.uri, new types.Range(2, 0, 0, 0)),
new types.Location(doc.uri, new types.Range(3, 0, 0, 0)),
new types.Location(doc.uri, new types.Range(4, 0, 0, 0)),
];
}
}));
@@ -436,7 +490,7 @@ suite('ExtHostLanguageFeatureCommands', function () {
provideTypeDefinition(doc: any): (vscode.Location | vscode.LocationLink)[] {
return [
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
{ targetUri: doc.uri, targetRange: new types.Range(0, 0, 0, 0), targetSelectionRange: new types.Range(1, 1, 1, 1), originSelectionRange: new types.Range(2, 2, 2, 2) }
{ targetUri: doc.uri, targetRange: new types.Range(1, 0, 0, 0), targetSelectionRange: new types.Range(1, 1, 1, 1), originSelectionRange: new types.Range(2, 2, 2, 2) }
];
}
}));
@@ -476,15 +530,21 @@ suite('ExtHostLanguageFeatureCommands', function () {
disposables.push(extHost.registerImplementationProvider(nullExtensionDescription, defaultSelector, <vscode.ImplementationProvider>{
provideImplementation(doc: any): any {
return new types.Location(doc.uri, new types.Range(0, 0, 0, 0));
return new types.Location(doc.uri, new types.Range(1, 0, 0, 0));
}
}));
disposables.push(extHost.registerImplementationProvider(nullExtensionDescription, defaultSelector, <vscode.ImplementationProvider>{
provideImplementation(doc: any): any {
// duplicate result will get removed
return new types.Location(doc.uri, new types.Range(1, 0, 0, 0));
}
}));
disposables.push(extHost.registerImplementationProvider(nullExtensionDescription, defaultSelector, <vscode.ImplementationProvider>{
provideImplementation(doc: any): any {
return [
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
new types.Location(doc.uri, new types.Range(2, 0, 0, 0)),
new types.Location(doc.uri, new types.Range(3, 0, 0, 0)),
new types.Location(doc.uri, new types.Range(4, 0, 0, 0)),
];
}
}));
@@ -505,7 +565,7 @@ suite('ExtHostLanguageFeatureCommands', function () {
provideImplementation(doc: any): (vscode.Location | vscode.LocationLink)[] {
return [
new types.Location(doc.uri, new types.Range(0, 0, 0, 0)),
{ targetUri: doc.uri, targetRange: new types.Range(0, 0, 0, 0), targetSelectionRange: new types.Range(1, 1, 1, 1), originSelectionRange: new types.Range(2, 2, 2, 2) }
{ targetUri: doc.uri, targetRange: new types.Range(1, 0, 0, 0), targetSelectionRange: new types.Range(1, 1, 1, 1), originSelectionRange: new types.Range(2, 2, 2, 2) }
];
}
}));
@@ -1147,7 +1207,7 @@ suite('ExtHostLanguageFeatureCommands', function () {
test('Inline Hints, back and forth', async function () {
disposables.push(extHost.registerInlineHintsProvider(nullExtensionDescription, defaultSelector, <vscode.InlineHintsProvider>{
provideInlineHints() {
return [new types.InlineHint('Foo', new types.Range(0, 1, 2, 3), undefined, true, false)];
return [new types.InlineHint('Foo', new types.Range(0, 1, 2, 3))];
}
}));
@@ -1167,13 +1227,15 @@ suite('ExtHostLanguageFeatureCommands', function () {
test('Inline Hints, merge', async function () {
disposables.push(extHost.registerInlineHintsProvider(nullExtensionDescription, defaultSelector, <vscode.InlineHintsProvider>{
provideInlineHints() {
return [new types.InlineHint('Bar', new types.Range(10, 11, 12, 13), undefined, true, false)];
return [new types.InlineHint('Bar', new types.Range(10, 11, 12, 13))];
}
}));
disposables.push(extHost.registerInlineHintsProvider(nullExtensionDescription, defaultSelector, <vscode.InlineHintsProvider>{
provideInlineHints() {
return [new types.InlineHint('Foo', new types.Range(0, 1, 2, 3), new types.MarkdownString('**Hello**'), true, false)];
const hint = new types.InlineHint('Foo', new types.Range(0, 1, 2, 3), types.InlineHintKind.Parameter);
hint.description = new types.MarkdownString('**Hello**');
return [hint];
}
}));
@@ -1201,7 +1263,7 @@ suite('ExtHostLanguageFeatureCommands', function () {
test('Inline Hints, bad provider', async function () {
disposables.push(extHost.registerInlineHintsProvider(nullExtensionDescription, defaultSelector, <vscode.InlineHintsProvider>{
provideInlineHints() {
return [new types.InlineHint('Foo', new types.Range(0, 1, 2, 3), undefined, true, false)];
return [new types.InlineHint('Foo', new types.Range(0, 1, 2, 3))];
}
}));
disposables.push(extHost.registerInlineHintsProvider(nullExtensionDescription, defaultSelector, <vscode.InlineHintsProvider>{

View File

@@ -24,7 +24,7 @@ suite('ExtHostBulkEdits.applyWorkspaceEdit', () => {
let rpcProtocol = new TestRPCProtocol();
rpcProtocol.set(MainContext.MainThreadBulkEdits, new class extends mock<MainThreadBulkEditsShape>() {
$tryApplyWorkspaceEdit(_workspaceResourceEdits: IWorkspaceEditDto): Promise<boolean> {
override $tryApplyWorkspaceEdit(_workspaceResourceEdits: IWorkspaceEditDto): Promise<boolean> {
workspaceResourceEdits = _workspaceResourceEdits;
return Promise.resolve(true);
}
@@ -40,7 +40,7 @@ suite('ExtHostBulkEdits.applyWorkspaceEdit', () => {
EOL: '\n',
}]
});
bulkEdits = new ExtHostBulkEdits(rpcProtocol, documentsAndEditors, null!);
bulkEdits = new ExtHostBulkEdits(rpcProtocol, documentsAndEditors);
});
test('uses version id if document available', async () => {

View File

@@ -18,10 +18,10 @@ suite('ExtHostCommands', function () {
let lastUnregister: string;
const shape = new class extends mock<MainThreadCommandsShape>() {
$registerCommand(id: string): void {
override $registerCommand(id: string): void {
//
}
$unregisterCommand(id: string): void {
override $unregisterCommand(id: string): void {
lastUnregister = id;
}
};
@@ -41,10 +41,10 @@ suite('ExtHostCommands', function () {
let unregisterCounter = 0;
const shape = new class extends mock<MainThreadCommandsShape>() {
$registerCommand(id: string): void {
override $registerCommand(id: string): void {
//
}
$unregisterCommand(id: string): void {
override $unregisterCommand(id: string): void {
unregisterCounter += 1;
}
};
@@ -65,10 +65,10 @@ suite('ExtHostCommands', function () {
let count = 0;
const shape = new class extends mock<MainThreadCommandsShape>() {
$registerCommand(id: string): void {
override $registerCommand(id: string): void {
//
}
async $executeCommand<T>(id: string, args: any[], retry: boolean): Promise<T | undefined> {
override async $executeCommand<T>(id: string, args: any[], retry: boolean): Promise<T | undefined> {
count++;
assert.strictEqual(retry, count === 1);
if (count === 1) {

View File

@@ -23,14 +23,14 @@ suite('ExtHostConfiguration', function () {
class RecordingShape extends mock<MainThreadConfigurationShape>() {
lastArgs!: [ConfigurationTarget, string, any];
$updateConfigurationOption(target: ConfigurationTarget, key: string, value: any): Promise<void> {
override $updateConfigurationOption(target: ConfigurationTarget, key: string, value: any): Promise<void> {
this.lastArgs = [target, key, value];
return Promise.resolve(undefined);
}
}
function createExtHostWorkspace(): ExtHostWorkspace {
return new ExtHostWorkspace(new TestRPCProtocol(), new class extends mock<IExtHostInitDataService>() { }, new class extends mock<IExtHostFileSystemInfo>() { getCapabilities() { return isLinux ? FileSystemProviderCapabilities.PathCaseSensitive : undefined; } }, new NullLogService());
return new ExtHostWorkspace(new TestRPCProtocol(), new class extends mock<IExtHostInitDataService>() { }, new class extends mock<IExtHostFileSystemInfo>() { override getCapabilities() { return isLinux ? FileSystemProviderCapabilities.PathCaseSensitive : undefined; } }, new NullLogService());
}
function createExtHostConfiguration(contents: any = Object.create(null), shape?: MainThreadConfigurationShape) {
@@ -318,7 +318,7 @@ suite('ExtHostConfiguration', function () {
'id': 'foo',
'folders': [aWorkspaceFolder(URI.file('foo'), 0)],
'name': 'foo'
});
}, true);
const testObject = new ExtHostConfigProvider(
new class extends mock<MainThreadConfigurationShape>() { },
extHostWorkspace,
@@ -394,7 +394,7 @@ suite('ExtHostConfiguration', function () {
'id': 'foo',
'folders': [aWorkspaceFolder(firstRoot, 0), aWorkspaceFolder(secondRoot, 1)],
'name': 'foo'
});
}, true);
const testObject = new ExtHostConfigProvider(
new class extends mock<MainThreadConfigurationShape>() { },
extHostWorkspace,
@@ -497,7 +497,7 @@ suite('ExtHostConfiguration', function () {
'id': 'foo',
'folders': [aWorkspaceFolder(firstRoot, 0), aWorkspaceFolder(secondRoot, 1)],
'name': 'foo'
});
}, true);
const testObject = new ExtHostConfigProvider(
new class extends mock<MainThreadConfigurationShape>() { },
extHostWorkspace,
@@ -656,7 +656,7 @@ suite('ExtHostConfiguration', function () {
test('update/error-state not OK', function () {
const shape = new class extends mock<MainThreadConfigurationShape>() {
$updateConfigurationOption(target: ConfigurationTarget, key: string, value: any): Promise<any> {
override $updateConfigurationOption(target: ConfigurationTarget, key: string, value: any): Promise<any> {
return Promise.reject(new Error('Unknown Key')); // something !== OK
}
};
@@ -675,7 +675,7 @@ suite('ExtHostConfiguration', function () {
'id': 'foo',
'folders': [workspaceFolder],
'name': 'foo'
});
}, true);
const testObject = new ExtHostConfigProvider(
new class extends mock<MainThreadConfigurationShape>() { },
extHostWorkspace,
@@ -731,7 +731,7 @@ suite('ExtHostConfiguration', function () {
function toConfigurationModel(obj: any): ConfigurationModel {
const parser = new ConfigurationModelParser('test');
parser.parseContent(JSON.stringify(obj));
parser.parse(JSON.stringify(obj));
return parser.configurationModel;
}

View File

@@ -25,14 +25,14 @@ suite('ExtHostDecorations', function () {
providers.clear();
mainThreadShape = new class extends mock<MainThreadDecorationsShape>() {
$registerDecorationProvider(handle: number) {
override $registerDecorationProvider(handle: number) {
providers.add(handle);
}
};
extHostDecorations = new ExtHostDecorations(
new class extends mock<IExtHostRpcService>() {
getProxy(): any {
override getProxy(): any {
return mainThreadShape;
}
},

View File

@@ -18,10 +18,10 @@ import { nullExtensionDescription } from 'vs/workbench/services/extensions/commo
suite('ExtHostDiagnostics', () => {
class DiagnosticsShape extends mock<MainThreadDiagnosticsShape>() {
$changeMany(owner: string, entries: [UriComponents, IMarkerData[]][]): void {
override $changeMany(owner: string, entries: [UriComponents, IMarkerData[]][]): void {
//
}
$clear(owner: string): void {
override $clear(owner: string): void {
//
}
}
@@ -164,7 +164,7 @@ suite('ExtHostDiagnostics', () => {
let lastEntries!: [UriComponents, IMarkerData[]][];
let collection = new DiagnosticCollection('test', 'test', 100, new class extends DiagnosticsShape {
$changeMany(owner: string, entries: [UriComponents, IMarkerData[]][]): void {
override $changeMany(owner: string, entries: [UriComponents, IMarkerData[]][]): void {
lastEntries = entries;
return super.$changeMany(owner, entries);
}
@@ -198,7 +198,7 @@ suite('ExtHostDiagnostics', () => {
const emitter = new Emitter<any>();
emitter.event(_ => eventCount += 1);
const collection = new DiagnosticCollection('test', 'test', 100, new class extends DiagnosticsShape {
$changeMany() {
override $changeMany() {
changeCount += 1;
}
}, emitter);
@@ -263,7 +263,7 @@ suite('ExtHostDiagnostics', () => {
let lastEntries!: [UriComponents, IMarkerData[]][];
let collection = new DiagnosticCollection('test', 'test', 250, new class extends DiagnosticsShape {
$changeMany(owner: string, entries: [UriComponents, IMarkerData[]][]): void {
override $changeMany(owner: string, entries: [UriComponents, IMarkerData[]][]): void {
lastEntries = entries;
return super.$changeMany(owner, entries);
}
@@ -350,7 +350,7 @@ suite('ExtHostDiagnostics', () => {
test('diagnostics with related information', function (done) {
let collection = new DiagnosticCollection('ddd', 'test', 100, new class extends DiagnosticsShape {
$changeMany(owner: string, entries: [UriComponents, IMarkerData[]][]) {
override $changeMany(owner: string, entries: [UriComponents, IMarkerData[]][]) {
let [[, data]] = entries;
assert.strictEqual(entries.length, 1);
@@ -408,7 +408,7 @@ suite('ExtHostDiagnostics', () => {
test('Error updating diagnostics from extension #60394', function () {
let callCount = 0;
let collection = new DiagnosticCollection('ddd', 'test', 100, new class extends DiagnosticsShape {
$changeMany(owner: string, entries: [UriComponents, IMarkerData[]][]) {
override $changeMany(owner: string, entries: [UriComponents, IMarkerData[]][]) {
callCount += 1;
}
}, new Emitter<any>());

View File

@@ -50,7 +50,7 @@ suite('ExtHostDocumentData', () => {
test('save, when disposed', function () {
let saved: URI;
let data = new ExtHostDocumentData(new class extends mock<MainThreadDocumentsShape>() {
$trySaveDocument(uri: URI) {
override $trySaveDocument(uri: URI) {
assert.ok(!saved);
saved = uri;
return Promise.resolve(true);
@@ -365,16 +365,16 @@ suite('ExtHostDocumentData updates line mapping', () => {
let line = 0, character = 0, previousIsCarriageReturn = false;
for (let offset = 0; offset <= allText.length; offset++) {
// The position coordinate system cannot express the position between \r and \n
const position = new Position(line, character + (previousIsCarriageReturn ? -1 : 0));
const position: Position = new Position(line, character + (previousIsCarriageReturn ? -1 : 0));
if (direction === AssertDocumentLineMappingDirection.OffsetToPosition) {
let actualPosition = doc.document.positionAt(offset);
assert.equal(positionToStr(actualPosition), positionToStr(position), 'positionAt mismatch for offset ' + offset);
assert.strictEqual(positionToStr(actualPosition), positionToStr(position), 'positionAt mismatch for offset ' + offset);
} else {
// The position coordinate system cannot express the position between \r and \n
let expectedOffset = offset + (previousIsCarriageReturn ? -1 : 0);
let expectedOffset: number = offset + (previousIsCarriageReturn ? -1 : 0);
let actualOffset = doc.document.offsetAt(position);
assert.equal(actualOffset, expectedOffset, 'offsetAt mismatch for position ' + positionToStr(position));
assert.strictEqual(actualOffset, expectedOffset, 'offsetAt mismatch for position ' + positionToStr(position));
}
if (allText.charAt(offset) === '\n') {

View File

@@ -379,7 +379,7 @@ suite('ExtHostDocumentSaveParticipant', () => {
test('Log failing listener', function () {
let didLogSomething = false;
let participant = new ExtHostDocumentSaveParticipant(new class extends NullLogService {
error(message: string | Error, ...args: any[]): void {
override error(message: string | Error, ...args: any[]): void {
didLogSomething = true;
}
}, documents, mainThreadBulkEdits);

View File

@@ -259,7 +259,7 @@ suite('ExtHostLanguageFeatures', function () {
}));
disposables.push(extHost.registerDefinitionProvider(defaultExtension, defaultSelector, new class implements vscode.DefinitionProvider {
provideDefinition(): any {
return new types.Location(model.uri, new types.Range(1, 1, 1, 1));
return new types.Location(model.uri, new types.Range(2, 1, 1, 1));
}
}));
@@ -591,7 +591,7 @@ suite('ExtHostLanguageFeatures', function () {
}));
await rpcProtocol.sync();
const { validActions: actions } = await getCodeActions(model, model.getFullModelRange(), { type: modes.CodeActionTriggerType.Manual }, Progress.None, CancellationToken.None);
const { validActions: actions } = await getCodeActions(model, model.getFullModelRange(), { type: modes.CodeActionTriggerType.Invoke }, Progress.None, CancellationToken.None);
assert.strictEqual(actions.length, 2);
const [first, second] = actions;
assert.strictEqual(first.action.title, 'Testing1');
@@ -615,7 +615,7 @@ suite('ExtHostLanguageFeatures', function () {
}));
await rpcProtocol.sync();
const { validActions: actions } = await getCodeActions(model, model.getFullModelRange(), { type: modes.CodeActionTriggerType.Manual }, Progress.None, CancellationToken.None);
const { validActions: actions } = await getCodeActions(model, model.getFullModelRange(), { type: modes.CodeActionTriggerType.Invoke }, Progress.None, CancellationToken.None);
assert.strictEqual(actions.length, 1);
const [first] = actions;
assert.strictEqual(first.action.title, 'Testing1');
@@ -638,7 +638,7 @@ suite('ExtHostLanguageFeatures', function () {
}));
await rpcProtocol.sync();
const { validActions: actions } = await getCodeActions(model, model.getFullModelRange(), { type: modes.CodeActionTriggerType.Manual }, Progress.None, CancellationToken.None);
const { validActions: actions } = await getCodeActions(model, model.getFullModelRange(), { type: modes.CodeActionTriggerType.Invoke }, Progress.None, CancellationToken.None);
assert.strictEqual(actions.length, 1);
});
@@ -656,7 +656,7 @@ suite('ExtHostLanguageFeatures', function () {
}));
await rpcProtocol.sync();
const { validActions: actions } = await getCodeActions(model, model.getFullModelRange(), { type: modes.CodeActionTriggerType.Manual }, Progress.None, CancellationToken.None);
const { validActions: actions } = await getCodeActions(model, model.getFullModelRange(), { type: modes.CodeActionTriggerType.Invoke }, Progress.None, CancellationToken.None);
assert.strictEqual(actions.length, 1);
});
@@ -966,7 +966,7 @@ suite('ExtHostLanguageFeatures', function () {
// --- format
const NullWorkerService = new class extends mock<IEditorWorkerService>() {
computeMoreMinimalEdits(resource: URI, edits: modes.TextEdit[] | null | undefined): Promise<modes.TextEdit[] | undefined> {
override computeMoreMinimalEdits(resource: URI, edits: modes.TextEdit[] | null | undefined): Promise<modes.TextEdit[] | undefined> {
return Promise.resolve(withNullAsUndefined(edits));
}
};

View File

@@ -11,6 +11,7 @@ import { ICommandService } from 'vs/platform/commands/common/commands';
import { mock } from 'vs/base/test/common/mock';
import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
import * as platform from 'vs/base/common/platform';
import { Event } from 'vs/base/common/event';
const emptyDialogService = new class implements IDialogService {
declare readonly _serviceBrand: undefined;
@@ -42,6 +43,8 @@ const emptyCommandService: ICommandService = {
const emptyNotificationService = new class implements INotificationService {
declare readonly _serviceBrand: undefined;
onDidAddNotification: Event<INotification> = Event.None;
onDidRemoveNotification: Event<INotification> = Event.None;
notify(...args: any[]): never {
throw new Error('not implemented');
}
@@ -71,6 +74,8 @@ class EmptyNotificationService implements INotificationService {
constructor(private withNotify: (notification: INotification) => void) {
}
onDidAddNotification: Event<INotification> = Event.None;
onDidRemoveNotification: Event<INotification> = Event.None;
notify(notification: INotification): INotificationHandle {
this.withNotify(notification);
@@ -112,7 +117,7 @@ suite('ExtHostMessageService', function () {
suite('modal', () => {
test('calls dialog service', async () => {
const service = new MainThreadMessageService(null!, emptyNotificationService, emptyCommandService, new class extends mock<IDialogService>() {
show(severity: Severity, message: string, buttons: string[]) {
override show(severity: Severity, message: string, buttons: string[]) {
assert.strictEqual(severity, 1);
assert.strictEqual(message, 'h');
assert.strictEqual(buttons.length, 2);
@@ -127,7 +132,7 @@ suite('ExtHostMessageService', function () {
test('returns undefined when cancelled', async () => {
const service = new MainThreadMessageService(null!, emptyNotificationService, emptyCommandService, new class extends mock<IDialogService>() {
show() {
override show() {
return Promise.resolve({ choice: 1 });
}
} as IDialogService);
@@ -138,7 +143,7 @@ suite('ExtHostMessageService', function () {
test('hides Cancel button when not needed', async () => {
const service = new MainThreadMessageService(null!, emptyNotificationService, emptyCommandService, new class extends mock<IDialogService>() {
show(severity: Severity, message: string, buttons: string[]) {
override show(severity: Severity, message: string, buttons: string[]) {
assert.strictEqual(buttons.length, 1);
return Promise.resolve({ choice: 0 });
}

View File

@@ -13,7 +13,7 @@ import { mock } from 'vs/base/test/common/mock';
import { IModelAddedData, MainContext, MainThreadCommandsShape, MainThreadNotebookShape } from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostNotebookController } from 'vs/workbench/api/common/extHostNotebook';
import { ExtHostNotebookDocument } from 'vs/workbench/api/common/extHostNotebookDocument';
import { CellKind, CellUri, NotebookCellsChangeType } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellKind, CellUri, NotebookCellExecutionState, NotebookCellsChangeType } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { URI } from 'vs/base/common/uri';
import { ExtHostDocuments } from 'vs/workbench/api/common/extHostDocuments';
import { ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
@@ -21,6 +21,7 @@ import { nullExtensionDescription } from 'vs/workbench/services/extensions/commo
import { isEqual } from 'vs/base/common/resources';
import { IExtensionStoragePaths } from 'vs/workbench/api/common/extHostStoragePaths';
import { generateUuid } from 'vs/base/common/uuid';
import { Event } from 'vs/base/common/event';
suite('NotebookCell#Document', function () {
@@ -33,25 +34,27 @@ suite('NotebookCell#Document', function () {
const notebookUri = URI.parse('test:///notebook.file');
const disposables = new DisposableStore();
setup(async function () {
teardown(function () {
disposables.clear();
});
setup(async function () {
rpcProtocol = new TestRPCProtocol();
rpcProtocol.set(MainContext.MainThreadCommands, new class extends mock<MainThreadCommandsShape>() {
$registerCommand() { }
override $registerCommand() { }
});
rpcProtocol.set(MainContext.MainThreadNotebook, new class extends mock<MainThreadNotebookShape>() {
async $registerNotebookProvider() { }
async $unregisterNotebookProvider() { }
override async $registerNotebookProvider() { }
override async $unregisterNotebookProvider() { }
});
extHostDocumentsAndEditors = new ExtHostDocumentsAndEditors(rpcProtocol, new NullLogService());
extHostDocuments = new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors);
const extHostStoragePaths = new class extends mock<IExtensionStoragePaths>() {
workspaceValue() {
override workspaceValue() {
return URI.from({ scheme: 'test', path: generateUuid() });
}
};
extHostNotebooks = new ExtHostNotebookController(rpcProtocol, new ExtHostCommands(rpcProtocol, new NullLogService()), extHostDocumentsAndEditors, { isExtensionDevelopmentDebug: false, webviewCspSource: '', webviewResourceRoot: '' }, new NullLogService(), extHostStoragePaths);
extHostNotebooks = new ExtHostNotebookController(rpcProtocol, new ExtHostCommands(rpcProtocol, new NullLogService()), extHostDocumentsAndEditors, extHostDocuments, new NullLogService(), extHostStoragePaths);
let reg = extHostNotebooks.registerNotebookContentProvider(nullExtensionDescription, 'test', new class extends mock<vscode.NotebookContentProvider>() {
// async openNotebook() { }
});
@@ -77,12 +80,11 @@ suite('NotebookCell#Document', function () {
cellKind: CellKind.Code,
outputs: [],
}],
contentOptions: { transientMetadata: {}, transientOutputs: false }
}],
addedEditors: [{
documentUri: notebookUri,
id: '_notebook_editor_0',
selections: [0],
selections: [{ start: 0, end: 1 }],
visibleRanges: []
}]
});
@@ -98,28 +100,28 @@ suite('NotebookCell#Document', function () {
test('cell document is vscode.TextDocument', async function () {
assert.strictEqual(notebook.notebookDocument.cells.length, 2);
assert.strictEqual(notebook.apiNotebook.cellCount, 2);
const [c1, c2] = notebook.notebookDocument.cells;
const d1 = extHostDocuments.getDocument(c1.uri);
const [c1, c2] = notebook.apiNotebook.getCells();
const d1 = extHostDocuments.getDocument(c1.document.uri);
assert.ok(d1);
assert.strictEqual(d1.languageId, c1.language);
assert.strictEqual(d1.languageId, c1.document.languageId);
assert.strictEqual(d1.version, 1);
assert.ok(d1.notebook === notebook.notebookDocument);
assert.ok(d1.notebook === notebook.apiNotebook);
const d2 = extHostDocuments.getDocument(c2.uri);
const d2 = extHostDocuments.getDocument(c2.document.uri);
assert.ok(d2);
assert.strictEqual(d2.languageId, c2.language);
assert.strictEqual(d2.languageId, c2.document.languageId);
assert.strictEqual(d2.version, 1);
assert.ok(d2.notebook === notebook.notebookDocument);
assert.ok(d2.notebook === notebook.apiNotebook);
});
test('cell document goes when notebook closes', async function () {
const cellUris: string[] = [];
for (let cell of notebook.notebookDocument.cells) {
assert.ok(extHostDocuments.getDocument(cell.uri));
cellUris.push(cell.uri.toString());
for (let cell of notebook.apiNotebook.getCells()) {
assert.ok(extHostDocuments.getDocument(cell.document.uri));
cellUris.push(cell.document.uri.toString());
}
const removedCellUris: string[] = [];
@@ -144,11 +146,11 @@ suite('NotebookCell#Document', function () {
const [first, second] = e.changes[0].items;
const doc1 = extHostDocuments.getAllDocumentData().find(data => isEqual(data.document.uri, first.uri));
const doc1 = extHostDocuments.getAllDocumentData().find(data => isEqual(data.document.uri, first.document.uri));
assert.ok(doc1);
assert.strictEqual(doc1?.document === first.document, true);
const doc2 = extHostDocuments.getAllDocumentData().find(data => isEqual(data.document.uri, second.uri));
const doc2 = extHostDocuments.getAllDocumentData().find(data => isEqual(data.document.uri, second.document.uri));
assert.ok(doc2);
assert.strictEqual(doc2?.document === second.document, true);
@@ -161,7 +163,7 @@ suite('NotebookCell#Document', function () {
});
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
kind: NotebookCellsChangeType.ModelChange,
@@ -194,10 +196,10 @@ suite('NotebookCell#Document', function () {
const docs: vscode.TextDocument[] = [];
const addData: IModelAddedData[] = [];
for (let cell of notebook.notebookDocument.cells) {
const doc = extHostDocuments.getDocument(cell.uri);
for (let cell of notebook.apiNotebook.getCells()) {
const doc = extHostDocuments.getDocument(cell.document.uri);
assert.ok(doc);
assert.strictEqual(extHostDocuments.getDocument(cell.uri).isClosed, false);
assert.strictEqual(extHostDocuments.getDocument(cell.document.uri).isClosed, false);
docs.push(doc);
addData.push({
EOL: '\n',
@@ -216,15 +218,15 @@ suite('NotebookCell#Document', function () {
extHostDocumentsAndEditors.$acceptDocumentsAndEditorsDelta({ removedDocuments: docs.map(d => d.uri) });
// notebook is still open -> cell documents stay open
for (let cell of notebook.notebookDocument.cells) {
assert.ok(extHostDocuments.getDocument(cell.uri));
assert.strictEqual(extHostDocuments.getDocument(cell.uri).isClosed, false);
for (let cell of notebook.apiNotebook.getCells()) {
assert.ok(extHostDocuments.getDocument(cell.document.uri));
assert.strictEqual(extHostDocuments.getDocument(cell.document.uri).isClosed, false);
}
// close notebook -> docs are closed
extHostNotebooks.$acceptDocumentAndEditorsDelta({ removedDocuments: [notebook.uri] });
for (let cell of notebook.notebookDocument.cells) {
assert.throws(() => extHostDocuments.getDocument(cell.uri));
for (let cell of notebook.apiNotebook.getCells()) {
assert.throws(() => extHostDocuments.getDocument(cell.document.uri));
}
for (let doc of docs) {
assert.strictEqual(doc.isClosed, true);
@@ -233,8 +235,8 @@ suite('NotebookCell#Document', function () {
test('cell document goes when cell is removed', async function () {
assert.strictEqual(notebook.notebookDocument.cells.length, 2);
const [cell1, cell2] = notebook.notebookDocument.cells;
assert.strictEqual(notebook.apiNotebook.cellCount, 2);
const [cell1, cell2] = notebook.apiNotebook.getCells();
extHostNotebooks.$acceptModelChanged(notebook.uri, {
versionId: 2,
@@ -246,40 +248,40 @@ suite('NotebookCell#Document', function () {
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1);
assert.strictEqual(notebook.apiNotebook.cellCount, 1);
assert.strictEqual(cell1.document.isClosed, true); // ref still alive!
assert.strictEqual(cell2.document.isClosed, false);
assert.throws(() => extHostDocuments.getDocument(cell1.uri));
assert.throws(() => extHostDocuments.getDocument(cell1.document.uri));
});
test('cell document knows notebook', function () {
for (let cells of notebook.notebookDocument.cells) {
assert.strictEqual(cells.document.notebook === notebook.notebookDocument, true);
for (let cells of notebook.apiNotebook.getCells()) {
assert.strictEqual(cells.document.notebook === notebook.apiNotebook, true);
}
});
test('cell#index', function () {
assert.strictEqual(notebook.notebookDocument.cells.length, 2);
const [first, second] = notebook.notebookDocument.cells;
assert.strictEqual(notebook.apiNotebook.cellCount, 2);
const [first, second] = notebook.apiNotebook.getCells();
assert.strictEqual(first.index, 0);
assert.strictEqual(second.index, 1);
// remove first cell
extHostNotebooks.$acceptModelChanged(notebook.uri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [{
kind: NotebookCellsChangeType.ModelChange,
changes: [[0, 1, []]]
}]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1);
assert.strictEqual(notebook.apiNotebook.cellCount, 1);
assert.strictEqual(second.index, 0);
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [{
kind: NotebookCellsChangeType.ModelChange,
changes: [[0, 0, [{
@@ -302,7 +304,138 @@ suite('NotebookCell#Document', function () {
}]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 3);
assert.strictEqual(notebook.apiNotebook.cellCount, 3);
assert.strictEqual(second.index, 2);
});
test('ERR MISSING extHostDocument for notebook cell: #116711', async function () {
const p = Event.toPromise(extHostNotebooks.onDidChangeNotebookCells);
// DON'T call this, make sure the cell-documents have not been created yet
// assert.strictEqual(notebook.notebookDocument.cellCount, 2);
extHostNotebooks.$acceptModelChanged(notebook.uri, {
versionId: 100,
rawEvents: [{
kind: NotebookCellsChangeType.ModelChange,
changes: [[0, 2, [{
handle: 3,
uri: CellUri.generate(notebookUri, 3),
source: ['### Heading'],
eol: '\n',
language: 'markdown',
cellKind: CellKind.Markdown,
outputs: [],
}, {
handle: 4,
uri: CellUri.generate(notebookUri, 4),
source: ['console.log("aaa")', 'console.log("bbb")'],
eol: '\n',
language: 'javascript',
cellKind: CellKind.Code,
outputs: [],
}]]]
}]
}, false);
assert.strictEqual(notebook.apiNotebook.cellCount, 2);
const event = await p;
assert.strictEqual(event.document === notebook.apiNotebook, true);
assert.strictEqual(event.changes.length, 1);
assert.strictEqual(event.changes[0].deletedCount, 2);
assert.strictEqual(event.changes[0].deletedItems[0].document.isClosed, true);
assert.strictEqual(event.changes[0].deletedItems[1].document.isClosed, true);
assert.strictEqual(event.changes[0].items.length, 2);
assert.strictEqual(event.changes[0].items[0].document.isClosed, false);
assert.strictEqual(event.changes[0].items[1].document.isClosed, false);
});
test('Opening a notebook results in VS Code firing the event onDidChangeActiveNotebookEditor twice #118470', function () {
let count = 0;
extHostNotebooks.onDidChangeActiveNotebookEditor(() => count += 1);
extHostNotebooks.$acceptDocumentAndEditorsDelta({
addedEditors: [{
documentUri: notebookUri,
id: '_notebook_editor_2',
selections: [{ start: 0, end: 1 }],
visibleRanges: []
}]
});
extHostNotebooks.$acceptDocumentAndEditorsDelta({
newActiveEditor: '_notebook_editor_2'
});
assert.strictEqual(count, 1);
});
test('unset active notebook editor', function () {
const editor = extHostNotebooks.activeNotebookEditor;
assert.ok(editor !== undefined);
extHostNotebooks.$acceptDocumentAndEditorsDelta({ newActiveEditor: undefined });
assert.ok(extHostNotebooks.activeNotebookEditor === editor);
extHostNotebooks.$acceptDocumentAndEditorsDelta({});
assert.ok(extHostNotebooks.activeNotebookEditor === editor);
extHostNotebooks.$acceptDocumentAndEditorsDelta({ newActiveEditor: null });
assert.ok(extHostNotebooks.activeNotebookEditor === undefined);
});
test('change cell language triggers onDidChange events', async function () {
const first = notebook.apiNotebook.cellAt(0);
assert.strictEqual(first.document.languageId, 'markdown');
const removed = Event.toPromise(extHostDocuments.onDidRemoveDocument);
const added = Event.toPromise(extHostDocuments.onDidAddDocument);
extHostNotebooks.$acceptModelChanged(notebook.uri, {
versionId: 12, rawEvents: [{
kind: NotebookCellsChangeType.ChangeLanguage,
index: 0,
language: 'fooLang'
}]
}, false);
const removedDoc = await removed;
const addedDoc = await added;
assert.strictEqual(first.document.languageId, 'fooLang');
assert.ok(removedDoc === addedDoc);
});
test('change cell execution state does not trigger onDidChangeMetadata event', async function () {
let didFireOnDidChangeMetadata = false;
let e = extHostNotebooks.onDidChangeCellMetadata(() => {
didFireOnDidChangeMetadata = true;
});
const changeExeState = Event.toPromise(extHostNotebooks.onDidChangeNotebookCellExecutionState);
extHostNotebooks.$acceptModelChanged(notebook.uri, {
versionId: 12, rawEvents: [{
kind: NotebookCellsChangeType.ChangeCellMetadata,
index: 0,
metadata: {
...notebook.getCellFromIndex(0)?.internalMetadata,
...{
runState: NotebookCellExecutionState.Executing
}
}
}]
}, false);
await changeExeState;
assert.strictEqual(didFireOnDidChangeMetadata, false);
e.dispose();
});
});

View File

@@ -38,20 +38,20 @@ suite('NotebookConcatDocument', function () {
rpcProtocol = new TestRPCProtocol();
rpcProtocol.set(MainContext.MainThreadCommands, new class extends mock<MainThreadCommandsShape>() {
$registerCommand() { }
override $registerCommand() { }
});
rpcProtocol.set(MainContext.MainThreadNotebook, new class extends mock<MainThreadNotebookShape>() {
async $registerNotebookProvider() { }
async $unregisterNotebookProvider() { }
override async $registerNotebookProvider() { }
override async $unregisterNotebookProvider() { }
});
extHostDocumentsAndEditors = new ExtHostDocumentsAndEditors(rpcProtocol, new NullLogService());
extHostDocuments = new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors);
const extHostStoragePaths = new class extends mock<IExtensionStoragePaths>() {
workspaceValue() {
override workspaceValue() {
return URI.from({ scheme: 'test', path: generateUuid() });
}
};
extHostNotebooks = new ExtHostNotebookController(rpcProtocol, new ExtHostCommands(rpcProtocol, new NullLogService()), extHostDocumentsAndEditors, { isExtensionDevelopmentDebug: false, webviewCspSource: '', webviewResourceRoot: '' }, new NullLogService(), extHostStoragePaths);
extHostNotebooks = new ExtHostNotebookController(rpcProtocol, new ExtHostCommands(rpcProtocol, new NullLogService()), extHostDocumentsAndEditors, extHostDocuments, new NullLogService(), extHostStoragePaths);
let reg = extHostNotebooks.registerNotebookContentProvider(nullExtensionDescription, 'test', new class extends mock<vscode.NotebookContentProvider>() {
// async openNotebook() { }
});
@@ -68,17 +68,14 @@ suite('NotebookConcatDocument', function () {
cellKind: CellKind.Markdown,
outputs: [],
}],
contentOptions: { transientOutputs: false, transientMetadata: {} },
versionId: 0
}],
addedEditors: [
{
documentUri: notebookUri,
id: '_notebook_editor_0',
selections: [0],
visibleRanges: []
}
]
addedEditors: [{
documentUri: notebookUri,
id: '_notebook_editor_0',
selections: [{ start: 0, end: 1 }],
visibleRanges: []
}]
});
extHostNotebooks.$acceptDocumentAndEditorsDelta({ newActiveEditor: '_notebook_editor_0' });
@@ -90,7 +87,7 @@ suite('NotebookConcatDocument', function () {
});
test('empty', function () {
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, undefined);
assert.strictEqual(doc.getText(), '');
assert.strictEqual(doc.version, 0);
@@ -126,7 +123,7 @@ suite('NotebookConcatDocument', function () {
const cellUri2 = CellUri.generate(notebook.uri, 2);
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [{
kind: NotebookCellsChangeType.ModelChange,
changes: [[0, 0, [{
@@ -151,9 +148,9 @@ suite('NotebookConcatDocument', function () {
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 2); // markdown and code
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, undefined);
assert.strictEqual(doc.contains(cellUri1), true);
assert.strictEqual(doc.contains(cellUri2), true);
@@ -163,7 +160,7 @@ suite('NotebookConcatDocument', function () {
test('location, position mapping', function () {
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
kind: NotebookCellsChangeType.ModelChange,
@@ -189,26 +186,26 @@ suite('NotebookConcatDocument', function () {
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 2); // markdown and code
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, undefined);
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');
assertLocation(doc, new Position(0, 0), new Location(notebook.notebookDocument.cells[0].uri, new Position(0, 0)));
assertLocation(doc, new Position(4, 0), new Location(notebook.notebookDocument.cells[1].uri, new Position(1, 0)));
assertLocation(doc, new Position(4, 3), new Location(notebook.notebookDocument.cells[1].uri, new Position(1, 3)));
assertLocation(doc, new Position(5, 11), new Location(notebook.notebookDocument.cells[1].uri, new Position(2, 11)));
assertLocation(doc, new Position(5, 12), new Location(notebook.notebookDocument.cells[1].uri, new Position(2, 11)), false); // don't check identity because position will be clamped
assertLocation(doc, new Position(0, 0), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(0, 0)));
assertLocation(doc, new Position(4, 0), new Location(notebook.apiNotebook.cellAt(1).document.uri, new Position(1, 0)));
assertLocation(doc, new Position(4, 3), new Location(notebook.apiNotebook.cellAt(1).document.uri, new Position(1, 3)));
assertLocation(doc, new Position(5, 11), new Location(notebook.apiNotebook.cellAt(1).document.uri, new Position(2, 11)));
assertLocation(doc, new Position(5, 12), new Location(notebook.apiNotebook.cellAt(1).document.uri, new Position(2, 11)), false); // don't check identity because position will be clamped
});
test('location, position mapping, cell changes', function () {
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, undefined);
// UPDATE 1
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
kind: NotebookCellsChangeType.ModelChange,
@@ -224,18 +221,18 @@ suite('NotebookConcatDocument', function () {
}
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 1);
assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 1);
assert.strictEqual(doc.version, 1);
assertLines(doc, 'Hello', 'World', 'Hello World!');
assertLocation(doc, new Position(0, 0), new Location(notebook.notebookDocument.cells[0].uri, new Position(0, 0)));
assertLocation(doc, new Position(2, 2), new Location(notebook.notebookDocument.cells[0].uri, new Position(2, 2)));
assertLocation(doc, new Position(4, 0), new Location(notebook.notebookDocument.cells[0].uri, new Position(2, 12)), false); // clamped
assertLocation(doc, new Position(0, 0), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(0, 0)));
assertLocation(doc, new Position(2, 2), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(2, 2)));
assertLocation(doc, new Position(4, 0), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(2, 12)), false); // clamped
// UPDATE 2
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
kind: NotebookCellsChangeType.ModelChange,
@@ -252,18 +249,18 @@ suite('NotebookConcatDocument', function () {
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2);
assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 2);
assert.strictEqual(doc.version, 2);
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');
assertLocation(doc, new Position(0, 0), new Location(notebook.notebookDocument.cells[0].uri, new Position(0, 0)));
assertLocation(doc, new Position(4, 0), new Location(notebook.notebookDocument.cells[1].uri, new Position(1, 0)));
assertLocation(doc, new Position(4, 3), new Location(notebook.notebookDocument.cells[1].uri, new Position(1, 3)));
assertLocation(doc, new Position(5, 11), new Location(notebook.notebookDocument.cells[1].uri, new Position(2, 11)));
assertLocation(doc, new Position(5, 12), new Location(notebook.notebookDocument.cells[1].uri, new Position(2, 11)), false); // don't check identity because position will be clamped
assertLocation(doc, new Position(0, 0), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(0, 0)));
assertLocation(doc, new Position(4, 0), new Location(notebook.apiNotebook.cellAt(1).document.uri, new Position(1, 0)));
assertLocation(doc, new Position(4, 3), new Location(notebook.apiNotebook.cellAt(1).document.uri, new Position(1, 3)));
assertLocation(doc, new Position(5, 11), new Location(notebook.apiNotebook.cellAt(1).document.uri, new Position(2, 11)));
assertLocation(doc, new Position(5, 12), new Location(notebook.apiNotebook.cellAt(1).document.uri, new Position(2, 11)), false); // don't check identity because position will be clamped
// UPDATE 3 (remove cell #2 again)
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
kind: NotebookCellsChangeType.ModelChange,
@@ -271,21 +268,21 @@ suite('NotebookConcatDocument', function () {
}
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 1);
assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 1);
assert.strictEqual(doc.version, 3);
assertLines(doc, 'Hello', 'World', 'Hello World!');
assertLocation(doc, new Position(0, 0), new Location(notebook.notebookDocument.cells[0].uri, new Position(0, 0)));
assertLocation(doc, new Position(2, 2), new Location(notebook.notebookDocument.cells[0].uri, new Position(2, 2)));
assertLocation(doc, new Position(4, 0), new Location(notebook.notebookDocument.cells[0].uri, new Position(2, 12)), false); // clamped
assertLocation(doc, new Position(0, 0), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(0, 0)));
assertLocation(doc, new Position(2, 2), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(2, 2)));
assertLocation(doc, new Position(4, 0), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(2, 12)), false); // clamped
});
test('location, position mapping, cell-document changes', function () {
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, undefined);
// UPDATE 1
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
@@ -310,21 +307,21 @@ suite('NotebookConcatDocument', function () {
}
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2);
assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 2);
assert.strictEqual(doc.version, 1);
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');
assertLocation(doc, new Position(0, 0), new Location(notebook.notebookDocument.cells[0].uri, new Position(0, 0)));
assertLocation(doc, new Position(2, 2), new Location(notebook.notebookDocument.cells[0].uri, new Position(2, 2)));
assertLocation(doc, new Position(2, 12), new Location(notebook.notebookDocument.cells[0].uri, new Position(2, 12)));
assertLocation(doc, new Position(4, 0), new Location(notebook.notebookDocument.cells[1].uri, new Position(1, 0)));
assertLocation(doc, new Position(4, 3), new Location(notebook.notebookDocument.cells[1].uri, new Position(1, 3)));
assertLocation(doc, new Position(0, 0), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(0, 0)));
assertLocation(doc, new Position(2, 2), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(2, 2)));
assertLocation(doc, new Position(2, 12), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(2, 12)));
assertLocation(doc, new Position(4, 0), new Location(notebook.apiNotebook.cellAt(1).document.uri, new Position(1, 0)));
assertLocation(doc, new Position(4, 3), new Location(notebook.apiNotebook.cellAt(1).document.uri, new Position(1, 3)));
// offset math
let cell1End = doc.offsetAt(new Position(2, 12));
assert.strictEqual(doc.positionAt(cell1End).isEqual(new Position(2, 12)), true);
extHostDocuments.$acceptModelChanged(notebook.notebookDocument.cells[0].uri, {
extHostDocuments.$acceptModelChanged(notebook.apiNotebook.cellAt(0).document.uri, {
versionId: 0,
eol: '\n',
changes: [{
@@ -335,7 +332,7 @@ suite('NotebookConcatDocument', function () {
}]
}, false);
assertLines(doc, 'Hello', 'World', 'Hi World!', 'Hallo', 'Welt', 'Hallo Welt!');
assertLocation(doc, new Position(2, 12), new Location(notebook.notebookDocument.cells[0].uri, new Position(2, 9)), false);
assertLocation(doc, new Position(2, 12), new Location(notebook.apiNotebook.cellAt(0).document.uri, new Position(2, 9)), false);
assert.strictEqual(doc.positionAt(cell1End).isEqual(new Position(3, 2)), true);
@@ -344,7 +341,7 @@ suite('NotebookConcatDocument', function () {
test('selector', function () {
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
kind: NotebookCellsChangeType.ModelChange,
@@ -369,16 +366,16 @@ suite('NotebookConcatDocument', function () {
]
}, false);
const mixedDoc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
const fooLangDoc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, 'fooLang');
const barLangDoc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, 'barLang');
const mixedDoc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, undefined);
const fooLangDoc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, 'fooLang');
const barLangDoc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, 'barLang');
assertLines(mixedDoc, 'fooLang-document', 'barLang-document');
assertLines(fooLangDoc, 'fooLang-document');
assertLines(barLangDoc, 'barLang-document');
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
kind: NotebookCellsChangeType.ModelChange,
@@ -416,7 +413,7 @@ suite('NotebookConcatDocument', function () {
test('offsetAt(position) <-> positionAt(offset)', function () {
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
kind: NotebookCellsChangeType.ModelChange,
@@ -441,9 +438,9 @@ suite('NotebookConcatDocument', function () {
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 2); // markdown and code
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, undefined);
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');
assertOffsetAtPosition(doc, 0, { line: 0, character: 0 });
@@ -473,7 +470,7 @@ suite('NotebookConcatDocument', function () {
test('locationAt(position) <-> positionAt(location)', function () {
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
kind: NotebookCellsChangeType.ModelChange,
@@ -498,23 +495,23 @@ suite('NotebookConcatDocument', function () {
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 2); // markdown and code
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, undefined);
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');
assertLocationAtPosition(doc, { line: 0, character: 0 }, { uri: notebook.notebookDocument.cells[0].uri, line: 0, character: 0 });
assertLocationAtPosition(doc, { line: 2, character: 0 }, { uri: notebook.notebookDocument.cells[0].uri, line: 2, character: 0 });
assertLocationAtPosition(doc, { line: 2, character: 12 }, { uri: notebook.notebookDocument.cells[0].uri, line: 2, character: 12 });
assertLocationAtPosition(doc, { line: 3, character: 0 }, { uri: notebook.notebookDocument.cells[1].uri, line: 0, character: 0 });
assertLocationAtPosition(doc, { line: 5, character: 0 }, { uri: notebook.notebookDocument.cells[1].uri, line: 2, character: 0 });
assertLocationAtPosition(doc, { line: 5, character: 11 }, { uri: notebook.notebookDocument.cells[1].uri, line: 2, character: 11 });
assertLocationAtPosition(doc, { line: 0, character: 0 }, { uri: notebook.apiNotebook.cellAt(0).document.uri, line: 0, character: 0 });
assertLocationAtPosition(doc, { line: 2, character: 0 }, { uri: notebook.apiNotebook.cellAt(0).document.uri, line: 2, character: 0 });
assertLocationAtPosition(doc, { line: 2, character: 12 }, { uri: notebook.apiNotebook.cellAt(0).document.uri, line: 2, character: 12 });
assertLocationAtPosition(doc, { line: 3, character: 0 }, { uri: notebook.apiNotebook.cellAt(1).document.uri, line: 0, character: 0 });
assertLocationAtPosition(doc, { line: 5, character: 0 }, { uri: notebook.apiNotebook.cellAt(1).document.uri, line: 2, character: 0 });
assertLocationAtPosition(doc, { line: 5, character: 11 }, { uri: notebook.apiNotebook.cellAt(1).document.uri, line: 2, character: 11 });
});
test('getText(range)', function () {
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
kind: NotebookCellsChangeType.ModelChange,
@@ -539,9 +536,9 @@ suite('NotebookConcatDocument', function () {
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 2); // markdown and code
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, undefined);
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');
assert.strictEqual(doc.getText(new Range(0, 0, 0, 0)), '');
@@ -552,7 +549,7 @@ suite('NotebookConcatDocument', function () {
test('validateRange/Position', function () {
extHostNotebooks.$acceptModelChanged(notebookUri, {
versionId: notebook.notebookDocument.version + 1,
versionId: notebook.apiNotebook.version + 1,
rawEvents: [
{
kind: NotebookCellsChangeType.ModelChange,
@@ -577,9 +574,9 @@ suite('NotebookConcatDocument', function () {
]
}, false);
assert.strictEqual(notebook.notebookDocument.cells.length, 1 + 2); // markdown and code
assert.strictEqual(notebook.apiNotebook.cellCount, 1 + 2); // markdown and code
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.notebookDocument, undefined);
let doc = new ExtHostNotebookConcatDocument(extHostNotebooks, extHostDocuments, notebook.apiNotebook, undefined);
assertLines(doc, 'Hello', 'World', 'Hello World!', 'Hallo', 'Welt', 'Hallo Welt!');

View File

@@ -0,0 +1,96 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { TestRPCProtocol } from 'vs/workbench/test/browser/api/testRPCProtocol';
import { ExtHostNotebookController } from 'vs/workbench/api/common/extHostNotebook';
import { nullExtensionDescription } from 'vs/workbench/services/extensions/common/extensions';
import { mock } from 'vs/workbench/test/common/workbenchTestServices';
import { INotebookKernelDto2, MainContext, MainThreadCommandsShape, MainThreadNotebookKernelsShape } from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostNotebookKernels } from 'vs/workbench/api/common/extHostNotebookKernels';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { IExtHostInitDataService } from 'vs/workbench/api/common/extHostInitDataService';
suite('NotebookKernel', function () {
let rpcProtocol: TestRPCProtocol;
let extHostNotebookKernels: ExtHostNotebookKernels;
const kernelData = new Map<number, INotebookKernelDto2>();
setup(async function () {
kernelData.clear();
rpcProtocol = new TestRPCProtocol();
rpcProtocol.set(MainContext.MainThreadCommands, new class extends mock<MainThreadCommandsShape>() {
override $registerCommand() { }
});
rpcProtocol.set(MainContext.MainThreadNotebookKernels, new class extends mock<MainThreadNotebookKernelsShape>() {
override async $addKernel(handle: number, data: INotebookKernelDto2): Promise<void> {
kernelData.set(handle, data);
}
override $removeKernel(handle: number) {
kernelData.delete(handle);
}
override $updateKernel(handle: number, data: Partial<INotebookKernelDto2>) {
assert.strictEqual(kernelData.has(handle), true);
kernelData.set(handle, { ...kernelData.get(handle)!, ...data, });
}
});
extHostNotebookKernels = new ExtHostNotebookKernels(
rpcProtocol,
new class extends mock<IExtHostInitDataService>() { },
new class extends mock<ExtHostNotebookController>() { }
);
});
test('create/dispose kernel', async function () {
const kernel = extHostNotebookKernels.createNotebookController(nullExtensionDescription, 'foo', '*', 'Foo');
assert.throws(() => (<any>kernel).id = 'dd');
assert.throws(() => (<any>kernel).viewType = 'dd');
assert.ok(kernel);
assert.strictEqual(kernel.id, 'foo');
assert.strictEqual(kernel.label, 'Foo');
assert.strictEqual(kernel.viewType, '*');
await rpcProtocol.sync();
assert.strictEqual(kernelData.size, 1);
let [first] = kernelData.values();
assert.strictEqual(first.id, 'nullExtensionDescription/foo');
assert.strictEqual(ExtensionIdentifier.equals(first.extensionId, nullExtensionDescription.identifier), true);
assert.strictEqual(first.label, 'Foo');
assert.strictEqual(first.viewType, '*');
kernel.dispose();
await rpcProtocol.sync();
assert.strictEqual(kernelData.size, 0);
});
test('update kernel', async function () {
const kernel = extHostNotebookKernels.createNotebookController(nullExtensionDescription, 'foo', '*', 'Foo');
await rpcProtocol.sync();
assert.ok(kernel);
let [first] = kernelData.values();
assert.strictEqual(first.id, 'nullExtensionDescription/foo');
assert.strictEqual(first.label, 'Foo');
kernel.label = 'Far';
assert.strictEqual(kernel.label, 'Far');
await rpcProtocol.sync();
[first] = kernelData.values();
assert.strictEqual(first.id, 'nullExtensionDescription/foo');
assert.strictEqual(first.label, 'Far');
});
});

View File

@@ -4,53 +4,58 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { MirroredTestCollection, TestItemFilteredWrapper } from 'vs/workbench/api/common/extHostTesting';
import * as convert from 'vs/workbench/api/common/extHostTypeConverters';
import { TestDiffOpType } from 'vs/workbench/contrib/testing/common/testCollection';
import { stubTest, testStubs } from 'vs/workbench/contrib/testing/common/testStubs';
import { TestOwnedTestCollection, TestSingleUseCollection } from 'vs/workbench/contrib/testing/test/common/ownedTestCollection';
import { TestChangeEvent, TestItem, TextDocument } from 'vscode';
import { CancellationToken } from 'vs/base/common/cancellation';
import { URI } from 'vs/base/common/uri';
import { Location } from 'vs/editor/common/modes';
import { Range } from 'vs/editor/common/core/range';
import { createDefaultDocumentTestRoot, TestItemFilteredWrapper } from 'vs/workbench/api/common/extHostTesting';
import * as convert from 'vs/workbench/api/common/extHostTypeConverters';
import { TestDiffOpType, TestItemExpandState } from 'vs/workbench/contrib/testing/common/testCollection';
import { stubTest, TestItemImpl, testStubs } from 'vs/workbench/contrib/testing/common/testStubs';
import { TestOwnedTestCollection, TestSingleUseCollection } from 'vs/workbench/contrib/testing/test/common/ownedTestCollection';
import { TestItem, TextDocument } from 'vscode';
const simplify = (item: TestItem) => {
if ('toJSON' in item) {
item = (item as any).toJSON();
delete (item as any).id;
delete (item as any).providerId;
delete (item as any).testId;
const simplify = (item: TestItem<unknown>) => ({
id: item.id,
label: item.label,
uri: item.uri,
range: item.range,
runnable: item.runnable,
debuggable: item.debuggable,
});
const assertTreesEqual = (a: TestItem<unknown> | undefined, b: TestItem<unknown> | undefined) => {
if (!a) {
throw new assert.AssertionError({ message: 'Expected a to be defined', actual: a });
}
return { ...item, children: undefined };
};
if (!b) {
throw new assert.AssertionError({ message: 'Expected b to be defined', actual: b });
}
const assertTreesEqual = (a: Readonly<TestItem>, b: Readonly<TestItem>) => {
assert.deepStrictEqual(simplify(a), simplify(b));
const aChildren = (a.children ?? []).sort();
const bChildren = (b.children ?? []).sort();
const aChildren = [...a.children.keys()].slice().sort();
const bChildren = [...b.children.keys()].slice().sort();
assert.strictEqual(aChildren.length, bChildren.length, `expected ${a.label}.children.length == ${b.label}.children.length`);
aChildren.forEach((_, i) => assertTreesEqual(aChildren[i], bChildren[i]));
aChildren.forEach(key => assertTreesEqual(a.children.get(key), b.children.get(key)));
};
const assertTreeListEqual = (a: ReadonlyArray<Readonly<TestItem>>, b: ReadonlyArray<Readonly<TestItem>>) => {
assert.strictEqual(a.length, b.length, `expected a.length == n.length`);
a.forEach((_, i) => assertTreesEqual(a[i], b[i]));
};
// const assertTreeListEqual = (a: ReadonlyArray<TestItem>, b: ReadonlyArray<TestItem>) => {
// assert.strictEqual(a.length, b.length, `expected a.length == n.length`);
// a.forEach((_, i) => assertTreesEqual(a[i], b[i]));
// };
class TestMirroredCollection extends MirroredTestCollection {
public changeEvent!: TestChangeEvent;
// class TestMirroredCollection extends MirroredTestCollection {
// public changeEvent!: TestChangeEvent;
constructor() {
super();
this.onDidChangeTests(evt => this.changeEvent = evt);
}
// constructor() {
// super();
// this.onDidChangeTests(evt => this.changeEvent = evt);
// }
public get length() {
return this.items.size;
}
}
// public get length() {
// return this.items.size;
// }
// }
suite('ExtHost Testing', () => {
let single: TestSingleUseCollection;
@@ -62,19 +67,47 @@ suite('ExtHost Testing', () => {
teardown(() => {
single.dispose();
assert.strictEqual(owned.idToInternal.size, 0, 'expected owned ids to be empty after dispose');
assert.strictEqual(!owned.idToInternal?.size, true, 'expected owned ids to be empty after dispose');
});
suite('OwnedTestCollection', () => {
test('adds a root recursively', () => {
const tests = testStubs.nested();
single.addRoot(tests, 'pid');
single.expand('id-root', Infinity);
assert.deepStrictEqual(single.collectDiff(), [
[TestDiffOpType.Add, { id: '0', providerId: 'pid', parent: null, item: convert.TestItem.from(stubTest('root')) }],
[TestDiffOpType.Add, { id: '1', providerId: 'pid', parent: '0', item: convert.TestItem.from(stubTest('a'), 'root') }],
[TestDiffOpType.Add, { id: '2', providerId: 'pid', parent: '1', item: convert.TestItem.from(stubTest('aa'), 'root\0a') }],
[TestDiffOpType.Add, { id: '3', providerId: 'pid', parent: '1', item: convert.TestItem.from(stubTest('ab'), 'root\0a') }],
[TestDiffOpType.Add, { id: '4', providerId: 'pid', parent: '0', item: convert.TestItem.from(stubTest('b'), 'root') }],
[
TestDiffOpType.Add,
{ src: { tree: 0, controller: 'pid' }, parent: null, expand: TestItemExpandState.BusyExpanding, item: { ...convert.TestItem.from(stubTest('root')) } }
],
[
TestDiffOpType.Add,
{ src: { tree: 0, controller: 'pid' }, parent: 'id-root', expand: TestItemExpandState.Expandable, item: { ...convert.TestItem.from(stubTest('a')) } }
],
[
TestDiffOpType.Add,
{ src: { tree: 0, controller: 'pid' }, parent: 'id-root', expand: TestItemExpandState.NotExpandable, item: convert.TestItem.from(stubTest('b')) }
],
[
TestDiffOpType.Update,
{ extId: 'id-root', expand: TestItemExpandState.Expanded }
],
[
TestDiffOpType.Update,
{ extId: 'id-a', expand: TestItemExpandState.BusyExpanding }
],
[
TestDiffOpType.Add,
{ src: { tree: 0, controller: 'pid' }, parent: 'id-a', expand: TestItemExpandState.NotExpandable, item: convert.TestItem.from(stubTest('aa')) }
],
[
TestDiffOpType.Add,
{ src: { tree: 0, controller: 'pid' }, parent: 'id-a', expand: TestItemExpandState.NotExpandable, item: convert.TestItem.from(stubTest('ab')) }
],
[
TestDiffOpType.Update,
{ extId: 'id-a', expand: TestItemExpandState.Expanded }
],
]);
});
@@ -88,229 +121,223 @@ suite('ExtHost Testing', () => {
test('watches property mutations', () => {
const tests = testStubs.nested();
single.addRoot(tests, 'pid');
single.expand('id-root', Infinity);
single.collectDiff();
tests.children![0].description = 'Hello world'; /* item a */
single.onItemChange(tests, 'pid');
assert.deepStrictEqual(single.collectDiff(), [
[TestDiffOpType.Update, { id: '1', parent: '0', providerId: 'pid', item: convert.TestItem.from({ ...stubTest('a'), description: 'Hello world' }, 'root') }],
]);
tests.children.get('id-a')!.description = 'Hello world'; /* item a */
single.onItemChange(tests, 'pid');
assert.deepStrictEqual(single.collectDiff(), []);
assert.deepStrictEqual(single.collectDiff(), [
[
TestDiffOpType.Update,
{ extId: 'id-a', item: { description: 'Hello world' } }],
]);
});
test('removes children', () => {
const tests = testStubs.nested();
single.addRoot(tests, 'pid');
single.expand('id-root', Infinity);
single.collectDiff();
tests.children!.splice(0, 1);
single.onItemChange(tests, 'pid');
tests.children.get('id-a')!.dispose();
assert.deepStrictEqual(single.collectDiff(), [
[TestDiffOpType.Remove, '1'],
[TestDiffOpType.Remove, 'id-a'],
]);
assert.deepStrictEqual([...owned.idToInternal.keys()].sort(), ['0', '4']);
assert.deepStrictEqual([...owned.idToInternal].map(n => n.item.extId).sort(), ['id-b', 'id-root']);
assert.strictEqual(single.itemToInternal.size, 2);
});
test('adds new children', () => {
const tests = testStubs.nested();
single.addRoot(tests, 'pid');
single.expand('id-root', Infinity);
single.collectDiff();
const child = stubTest('ac');
tests.children![0].children!.push(child);
single.onItemChange(tests, 'pid');
tests.children.get('id-a')!.addChild(child);
assert.deepStrictEqual(single.collectDiff(), [
[TestDiffOpType.Add, { id: '5', providerId: 'pid', parent: '1', item: convert.TestItem.from(child, 'root\0a') }],
[TestDiffOpType.Add, {
src: { tree: 0, controller: 'pid' },
parent: 'id-a',
expand: TestItemExpandState.NotExpandable,
item: convert.TestItem.from(child),
}],
]);
assert.deepStrictEqual([...owned.idToInternal.keys()].sort(), ['0', '1', '2', '3', '4', '5']);
assert.deepStrictEqual(
[...owned.idToInternal].map(n => n.item.extId).sort(),
['id-a', 'id-aa', 'id-ab', 'id-ac', 'id-b', 'id-root'],
);
assert.strictEqual(single.itemToInternal.size, 6);
});
});
suite('MirroredTestCollection', () => {
let m: TestMirroredCollection;
setup(() => m = new TestMirroredCollection());
// todo@connor4312: re-renable when we figure out what observing looks like we async children
// let m: TestMirroredCollection;
// setup(() => m = new TestMirroredCollection());
test('mirrors creation of the root', () => {
const tests = testStubs.nested();
single.addRoot(tests, 'pid');
m.apply(single.collectDiff());
assertTreesEqual(m.rootTestItems[0], owned.getTestById('0')!.actual);
assert.strictEqual(m.length, single.itemToInternal.size);
});
// test('mirrors creation of the root', () => {
// const tests = testStubs.nested();
// single.addRoot(tests, 'pid');
// single.expand('id-root', Infinity);
// m.apply(single.collectDiff());
// assertTreesEqual(m.rootTestItems[0], owned.getTestById('id-root')![1].actual);
// assert.strictEqual(m.length, single.itemToInternal.size);
// });
test('mirrors node deletion', () => {
const tests = testStubs.nested();
single.addRoot(tests, 'pid');
m.apply(single.collectDiff());
tests.children!.splice(0, 1);
single.onItemChange(tests, 'pid');
m.apply(single.collectDiff());
// test('mirrors node deletion', () => {
// const tests = testStubs.nested();
// single.addRoot(tests, 'pid');
// m.apply(single.collectDiff());
// single.expand('id-root', Infinity);
// tests.children!.splice(0, 1);
// single.onItemChange(tests, 'pid');
// single.expand('id-root', Infinity);
// m.apply(single.collectDiff());
assertTreesEqual(m.rootTestItems[0], owned.getTestById('0')!.actual);
assert.strictEqual(m.length, single.itemToInternal.size);
});
// assertTreesEqual(m.rootTestItems[0], owned.getTestById('id-root')![1].actual);
// assert.strictEqual(m.length, single.itemToInternal.size);
// });
test('mirrors node addition', () => {
const tests = testStubs.nested();
single.addRoot(tests, 'pid');
m.apply(single.collectDiff());
tests.children![0].children!.push(stubTest('ac'));
single.onItemChange(tests, 'pid');
m.apply(single.collectDiff());
// test('mirrors node addition', () => {
// const tests = testStubs.nested();
// single.addRoot(tests, 'pid');
// m.apply(single.collectDiff());
// tests.children![0].children!.push(stubTest('ac'));
// single.onItemChange(tests, 'pid');
// m.apply(single.collectDiff());
assertTreesEqual(m.rootTestItems[0], owned.getTestById('0')!.actual);
assert.strictEqual(m.length, single.itemToInternal.size);
});
// assertTreesEqual(m.rootTestItems[0], owned.getTestById('id-root')![1].actual);
// assert.strictEqual(m.length, single.itemToInternal.size);
// });
test('mirrors node update', () => {
const tests = testStubs.nested();
single.addRoot(tests, 'pid');
m.apply(single.collectDiff());
tests.children![0].description = 'Hello world'; /* item a */
single.onItemChange(tests, 'pid');
m.apply(single.collectDiff());
// test('mirrors node update', () => {
// const tests = testStubs.nested();
// single.addRoot(tests, 'pid');
// m.apply(single.collectDiff());
// tests.children![0].description = 'Hello world'; /* item a */
// single.onItemChange(tests, 'pid');
// m.apply(single.collectDiff());
assertTreesEqual(m.rootTestItems[0], owned.getTestById('0')!.actual);
});
// assertTreesEqual(m.rootTestItems[0], owned.getTestById('id-root')![1].actual);
// });
suite('MirroredChangeCollector', () => {
let tests = testStubs.nested();
setup(() => {
tests = testStubs.nested();
single.addRoot(tests, 'pid');
m.apply(single.collectDiff());
});
// suite('MirroredChangeCollector', () => {
// let tests = testStubs.nested();
// setup(() => {
// tests = testStubs.nested();
// single.addRoot(tests, 'pid');
// m.apply(single.collectDiff());
// });
test('creates change for root', () => {
assert.deepStrictEqual(m.changeEvent.commonChangeAncestor, null);
assertTreeListEqual(m.changeEvent.added, [
tests,
tests.children[0],
tests.children![0].children![0],
tests.children![0].children![1],
tests.children[1],
]);
assertTreeListEqual(m.changeEvent.removed, []);
assertTreeListEqual(m.changeEvent.updated, []);
});
// test('creates change for root', () => {
// assertTreeListEqual(m.changeEvent.added, [
// tests,
// tests.children[0],
// tests.children![0].children![0],
// tests.children![0].children![1],
// tests.children[1],
// ]);
// assertTreeListEqual(m.changeEvent.removed, []);
// assertTreeListEqual(m.changeEvent.updated, []);
// });
test('creates change for delete', () => {
const rm = tests.children.shift()!;
single.onItemChange(tests, 'pid');
m.apply(single.collectDiff());
// test('creates change for delete', () => {
// const rm = tests.children.shift()!;
// single.onItemChange(tests, 'pid');
// m.apply(single.collectDiff());
assertTreesEqual(m.changeEvent.commonChangeAncestor!, tests);
assertTreeListEqual(m.changeEvent.added, []);
assertTreeListEqual(m.changeEvent.removed, [
{ ...rm, children: [] },
{ ...rm.children![0], children: [] },
{ ...rm.children![1], children: [] },
]);
assertTreeListEqual(m.changeEvent.updated, []);
});
// assertTreeListEqual(m.changeEvent.added, []);
// assertTreeListEqual(m.changeEvent.removed, [
// { ...rm },
// { ...rm.children![0] },
// { ...rm.children![1] },
// ]);
// assertTreeListEqual(m.changeEvent.updated, []);
// });
test('creates change for update', () => {
tests.children[0].label = 'updated!';
single.onItemChange(tests, 'pid');
m.apply(single.collectDiff());
// test('creates change for update', () => {
// tests.children[0].label = 'updated!';
// single.onItemChange(tests, 'pid');
// m.apply(single.collectDiff());
assert.deepStrictEqual(m.changeEvent.commonChangeAncestor?.label, 'updated!');
assertTreeListEqual(m.changeEvent.added, []);
assertTreeListEqual(m.changeEvent.removed, []);
assertTreeListEqual(m.changeEvent.updated, [tests.children[0]]);
});
// assertTreeListEqual(m.changeEvent.added, []);
// assertTreeListEqual(m.changeEvent.removed, []);
// assertTreeListEqual(m.changeEvent.updated, [tests.children[0]]);
// });
test('is a no-op if a node is added and removed', () => {
const nested = testStubs.nested();
tests.children.push(nested);
single.onItemChange(tests, 'pid');
tests.children.pop();
single.onItemChange(tests, 'pid');
const previousEvent = m.changeEvent;
m.apply(single.collectDiff());
assert.strictEqual(m.changeEvent, previousEvent);
});
// test('is a no-op if a node is added and removed', () => {
// const nested = testStubs.nested('id2-');
// tests.children.push(nested);
// single.onItemChange(tests, 'pid');
// tests.children.pop();
// single.onItemChange(tests, 'pid');
// const previousEvent = m.changeEvent;
// m.apply(single.collectDiff());
// assert.strictEqual(m.changeEvent, previousEvent);
// });
test('is a single-op if a node is added and changed', () => {
const child = stubTest('c');
tests.children.push(child);
single.onItemChange(tests, 'pid');
child.label = 'd';
single.onItemChange(tests, 'pid');
m.apply(single.collectDiff());
// test('is a single-op if a node is added and changed', () => {
// const child = stubTest('c');
// tests.children.push(child);
// single.onItemChange(tests, 'pid');
// child.label = 'd';
// single.onItemChange(tests, 'pid');
// m.apply(single.collectDiff());
assert.strictEqual(m.changeEvent.commonChangeAncestor?.label, 'root');
assertTreeListEqual(m.changeEvent.added, [child]);
assertTreeListEqual(m.changeEvent.removed, []);
assertTreeListEqual(m.changeEvent.updated, []);
});
// assertTreeListEqual(m.changeEvent.added, [child]);
// assertTreeListEqual(m.changeEvent.removed, []);
// assertTreeListEqual(m.changeEvent.updated, []);
// });
test('gets the common ancestor (1)', () => {
tests.children![0].children![0].label = 'za';
tests.children![0].children![1].label = 'zb';
single.onItemChange(tests, 'pid');
m.apply(single.collectDiff());
// test('gets the common ancestor (1)', () => {
// tests.children![0].children![0].label = 'za';
// tests.children![0].children![1].label = 'zb';
// single.onItemChange(tests, 'pid');
// m.apply(single.collectDiff());
assert.strictEqual(m.changeEvent.commonChangeAncestor?.label, 'a');
});
// });
test('gets the common ancestor (2)', () => {
tests.children![0].children![0].label = 'za';
tests.children![1].label = 'ab';
single.onItemChange(tests, 'pid');
m.apply(single.collectDiff());
assert.strictEqual(m.changeEvent.commonChangeAncestor?.label, 'root');
});
});
// test('gets the common ancestor (2)', () => {
// tests.children![0].children![0].label = 'za';
// tests.children![1].label = 'ab';
// single.onItemChange(tests, 'pid');
// m.apply(single.collectDiff());
// });
// });
suite('TestItemFilteredWrapper', () => {
const stubTestWithLocation = (label: string, location: Location): TestItem => {
const t = stubTest(label);
t.location = location as any;
return t;
};
const location1: Location = {
range: new Range(0, 0, 0, 0),
uri: URI.parse('file:///foo.ts')
};
const location2: Location = {
range: new Range(0, 0, 0, 0),
uri: URI.parse('file:///bar.ts')
};
const location3: Location = {
range: new Range(0, 0, 0, 0),
uri: URI.parse('file:///baz.ts')
};
const textDocumentFilter = {
uri: location1.uri
uri: URI.parse('file:///foo.ts'),
} as TextDocument;
let testsWithLocation: TestItem;
setup(() => {
testsWithLocation = {
...stubTest('root'),
children: [
{
...stubTestWithLocation('a', location1),
children: [stubTestWithLocation('aa', location1), stubTestWithLocation('ab', location1)]
},
{
...stubTestWithLocation('b', location2),
children: [stubTestWithLocation('ba', location2), stubTestWithLocation('bb', location2)]
},
{
...stubTestWithLocation('b', location3),
let testsWithLocation: TestItemImpl;
setup(async () => {
testsWithLocation =
stubTest('root', undefined, [
stubTest('a', undefined, [
stubTest('aa', undefined, undefined, URI.parse('file:///foo.ts')),
stubTest('ab', undefined, undefined, URI.parse('file:///foo.ts'))
], URI.parse('file:///foo.ts')),
stubTest('b', undefined, [
stubTest('ba', undefined, undefined, URI.parse('file:///bar.ts')),
stubTest('bb', undefined, undefined, URI.parse('file:///bar.ts'))
], URI.parse('file:///bar.ts')),
stubTest('c', undefined, undefined, URI.parse('file:///baz.ts')),
]);
// todo: this is not used, don't think it's needed anymore
await createDefaultDocumentTestRoot<void>(
{
createWorkspaceTestRoot: () => testsWithLocation as TestItem<void>,
runTests() {
throw new Error('no implemented');
}
],
};
},
textDocumentFilter,
undefined,
CancellationToken.None
);
});
teardown(() => {
@@ -318,37 +345,41 @@ suite('ExtHost Testing', () => {
});
test('gets all actual properties', () => {
const testItem: TestItem = stubTest('test1');
const wrapper: TestItemFilteredWrapper = TestItemFilteredWrapper.getWrapperForTestItem(testItem, textDocumentFilter);
const testItem = stubTest('test1');
const wrapper = TestItemFilteredWrapper.getWrapperForTestItem(testItem, textDocumentFilter);
assert.strictEqual(testItem.debuggable, wrapper.debuggable);
assert.strictEqual(testItem.description, wrapper.description);
assert.strictEqual(testItem.label, wrapper.label);
assert.strictEqual(testItem.location, wrapper.location);
assert.strictEqual(testItem.uri, wrapper.uri);
assert.strictEqual(testItem.runnable, wrapper.runnable);
assert.strictEqual(testItem.state, wrapper.state);
});
test('gets no children if nothing matches Uri filter', () => {
let tests: TestItem = testStubs.nested();
const tests = testStubs.nested();
const wrapper = TestItemFilteredWrapper.getWrapperForTestItem(tests, textDocumentFilter);
assert.strictEqual(wrapper.children.length, 0);
wrapper.resolveHandler?.(CancellationToken.None);
assert.strictEqual(wrapper.children.size, 0);
});
test('filter is applied to children', () => {
const wrapper = TestItemFilteredWrapper.getWrapperForTestItem(testsWithLocation, textDocumentFilter);
assert.strictEqual(wrapper.label, 'root');
assert.strictEqual(wrapper.children.length, 1);
assert.strictEqual(wrapper.children[0] instanceof TestItemFilteredWrapper, true);
assert.strictEqual(wrapper.children[0].label, 'a');
wrapper.resolveHandler?.(CancellationToken.None);
const children = [...wrapper.children.values()];
assert.strictEqual(children.length, 1);
assert.strictEqual(children[0] instanceof TestItemFilteredWrapper, true);
assert.strictEqual(children[0].label, 'a');
});
test('can get if node has matching filter', () => {
const rootWrapper = TestItemFilteredWrapper.getWrapperForTestItem(testsWithLocation, textDocumentFilter);
rootWrapper.resolveHandler?.(CancellationToken.None);
const invisible = testsWithLocation.children![1];
const invisible = testsWithLocation.children.get('id-b')!;
const invisibleWrapper = TestItemFilteredWrapper.getWrapperForTestItem(invisible, textDocumentFilter);
const visible = testsWithLocation.children![0];
const visible = testsWithLocation.children.get('id-a')!;
const visibleWrapper = TestItemFilteredWrapper.getWrapperForTestItem(visible, textDocumentFilter);
// The root is always visible
@@ -357,50 +388,39 @@ suite('ExtHost Testing', () => {
assert.strictEqual(visibleWrapper.hasNodeMatchingFilter, true);
});
test('can get visible parent', () => {
const rootWrapper = TestItemFilteredWrapper.getWrapperForTestItem(testsWithLocation, textDocumentFilter);
const invisible = testsWithLocation.children![1];
const invisibleWrapper = TestItemFilteredWrapper.getWrapperForTestItem(invisible, textDocumentFilter);
const visible = testsWithLocation.children![0];
const visibleWrapper = TestItemFilteredWrapper.getWrapperForTestItem(visible, textDocumentFilter);
// The root is always visible
assert.strictEqual(rootWrapper.visibleParent, rootWrapper);
assert.strictEqual(invisibleWrapper.visibleParent, rootWrapper);
assert.strictEqual(visibleWrapper.visibleParent, visibleWrapper);
});
test('can reset cached value of hasNodeMatchingFilter', () => {
TestItemFilteredWrapper.getWrapperForTestItem(testsWithLocation, textDocumentFilter);
const wrapper = TestItemFilteredWrapper.getWrapperForTestItem(testsWithLocation, textDocumentFilter);
wrapper.resolveHandler?.(CancellationToken.None);
const invisible = testsWithLocation.children![1];
const invisible = testsWithLocation.children.get('id-b')!;
const invisibleWrapper = TestItemFilteredWrapper.getWrapperForTestItem(invisible, textDocumentFilter);
assert.strictEqual(wrapper.children.get('id-b'), undefined);
assert.strictEqual(invisibleWrapper.hasNodeMatchingFilter, false);
invisible.location = location1 as any;
assert.strictEqual(invisibleWrapper.hasNodeMatchingFilter, false);
invisibleWrapper.reset();
invisible.addChild(stubTest('bc', undefined, undefined, URI.parse('file:///foo.ts')));
assert.strictEqual(invisibleWrapper.hasNodeMatchingFilter, true);
assert.strictEqual(invisibleWrapper.children.size, 1);
assert.strictEqual(wrapper.children.get('id-b'), invisibleWrapper);
});
test('can reset cached value of hasNodeMatchingFilter of parents up to visible parent', () => {
const rootWrapper = TestItemFilteredWrapper.getWrapperForTestItem(testsWithLocation, textDocumentFilter);
// test('can reset cached value of hasNodeMatchingFilter of parents up to visible parent', () => {
// const rootWrapper = TestItemFilteredWrapper.getWrapperForTestItem(testsWithLocation, textDocumentFilter);
const invisibleParent = testsWithLocation.children![1];
const invisibleParentWrapper = TestItemFilteredWrapper.getWrapperForTestItem(invisibleParent, textDocumentFilter);
const invisible = invisibleParent.children![1];
const invisibleWrapper = TestItemFilteredWrapper.getWrapperForTestItem(invisible, textDocumentFilter);
// const invisibleParent = testsWithLocation.children.get('id-b')!;
// const invisibleParentWrapper = TestItemFilteredWrapper.getWrapperForTestItem(invisibleParent, textDocumentFilter);
// const invisible = invisibleParent.children.get('id-bb')!;
// const invisibleWrapper = TestItemFilteredWrapper.getWrapperForTestItem(invisible, textDocumentFilter);
assert.strictEqual(invisibleParentWrapper.hasNodeMatchingFilter, false);
invisible.location = location1 as any;
assert.strictEqual(invisibleParentWrapper.hasNodeMatchingFilter, false);
invisibleWrapper.reset();
assert.strictEqual(invisibleParentWrapper.hasNodeMatchingFilter, true);
// assert.strictEqual(invisibleParentWrapper.hasNodeMatchingFilter, false);
// invisible.location = location1 as any;
// assert.strictEqual(invisibleParentWrapper.hasNodeMatchingFilter, false);
// invisibleWrapper.reset();
// assert.strictEqual(invisibleParentWrapper.hasNodeMatchingFilter, true);
// the root should be undefined due to the reset.
assert.strictEqual((rootWrapper as any).matchesFilter, undefined);
});
// // the root should be undefined due to the reset.
// assert.strictEqual((rootWrapper as any).matchesFilter, undefined);
// });
});
});
});

View File

@@ -44,7 +44,7 @@ suite('ExtHostTextEditor', () => {
let applyCount = 0;
let editor = new ExtHostTextEditor('edt1',
new class extends mock<MainThreadTextEditorsShape>() {
$tryApplyEdits(): Promise<boolean> {
override $tryApplyEdits(): Promise<boolean> {
applyCount += 1;
return Promise.resolve(true);
}

View File

@@ -26,16 +26,16 @@ suite.skip('ExtHostTreeView', function () {
onRefresh = new Emitter<{ [treeItemHandle: string]: ITreeItem }>();
$registerTreeViewDataProvider(treeViewId: string): void {
override async $registerTreeViewDataProvider(treeViewId: string): Promise<void> {
}
$refresh(viewId: string, itemsToRefresh: { [treeItemHandle: string]: ITreeItem }): Promise<void> {
override $refresh(viewId: string, itemsToRefresh: { [treeItemHandle: string]: ITreeItem }): Promise<void> {
return Promise.resolve(null).then(() => {
this.onRefresh.fire(itemsToRefresh);
});
}
$reveal(): Promise<void> {
override $reveal(): Promise<void> {
return Promise.resolve();
}
@@ -604,7 +604,7 @@ suite.skip('ExtHostTreeView', function () {
const treeView = testObject.createTreeView('treeDataProvider', { treeDataProvider: aCompleteNodeTreeDataProvider() }, { enableProposedApi: true } as IExtensionDescription);
return loadCompleteTree('treeDataProvider')
.then(() => {
runWithEventMerging((resolve) => {
return runWithEventMerging((resolve) => {
tree = {
'a': {
'aa': {},
@@ -633,9 +633,9 @@ suite.skip('ExtHostTreeView', function () {
.then(() => {
assert.ok(revealTarget.calledOnce);
assert.deepStrictEqual('treeDataProvider', revealTarget.args[0][0]);
assert.deepStrictEqual({ handle: '0/0:b/0:bc', label: { label: 'bc' }, collapsibleState: TreeItemCollapsibleState.None, parentHandle: '0/0:b' }, removeUnsetKeys(revealTarget.args[0][1]));
assert.deepStrictEqual([{ handle: '0/0:b', label: { label: 'b' }, collapsibleState: TreeItemCollapsibleState.Collapsed }], (<Array<any>>revealTarget.args[0][2]).map(arg => removeUnsetKeys(arg)));
assert.deepStrictEqual({ select: true, focus: false, expand: false }, revealTarget.args[0][3]);
assert.deepStrictEqual({ handle: '0/0:b/0:bc', label: { label: 'bc' }, collapsibleState: TreeItemCollapsibleState.None, parentHandle: '0/0:b' }, removeUnsetKeys(revealTarget.args[0][1].item));
assert.deepStrictEqual([{ handle: '0/0:b', label: { label: 'b' }, collapsibleState: TreeItemCollapsibleState.Collapsed }], (<Array<any>>revealTarget.args[0][1].parentChain).map(arg => removeUnsetKeys(arg)));
assert.deepStrictEqual({ select: true, focus: false, expand: false }, revealTarget.args[0][2]);
});
});
});

View File

@@ -8,6 +8,7 @@ import { URI } from 'vs/base/common/uri';
import * as types from 'vs/workbench/api/common/extHostTypes';
import { isWindows } from 'vs/base/common/platform';
import { assertType } from 'vs/base/common/types';
import { notebookDocumentMetadataDefaults } from 'vs/workbench/contrib/notebook/common/notebookCommon';
function assertToJSON(a: any, expected: any) {
const raw = JSON.stringify(a);
@@ -648,4 +649,57 @@ suite('ExtHostTypes', function () {
assert.deepStrictEqual(md.value, '\n```html\n<img src=0 onerror="alert(1)">\n```\n');
});
test('NotebookMetadata - defaults', function () {
const obj = new types.NotebookDocumentMetadata();
assert.strictEqual(obj.trusted, notebookDocumentMetadataDefaults.trusted);
});
test('NotebookMetadata - with', function () {
const obj = new types.NotebookDocumentMetadata();
const newObj = obj.with({ trusted: false });
assert.ok(obj !== newObj);
const sameObj = newObj.with({ trusted: false });
assert.ok(newObj === sameObj);
assert.strictEqual(obj.trusted, true);
assert.strictEqual(newObj.trusted, false);
});
test('NotebookMetadata - with custom', function () {
const obj = new types.NotebookDocumentMetadata();
const newObj = obj.with({ trusted: false, mycustom: { display: 'hello' } });
assert.ok(obj !== newObj);
const sameObj = newObj.with({ trusted: false });
assert.ok(newObj === sameObj);
assert.strictEqual(obj.trusted, true);
assert.strictEqual(newObj.trusted, false);
assert.deepStrictEqual(newObj.mycustom, { display: 'hello' });
});
test('NotebookCellMetadata - with', function () {
const obj = new types.NotebookCellMetadata(true, true);
const newObj = obj.with({ inputCollapsed: false });
assert.ok(obj !== newObj);
assert.strictEqual(obj.inputCollapsed, true);
assert.strictEqual(obj.custom, undefined);
assert.strictEqual(newObj.inputCollapsed, false);
assert.strictEqual(newObj.custom, undefined);
});
test('NotebookCellMetadata - with custom', function () {
const obj = new types.NotebookCellMetadata(true, true);
const newObj = obj.with({ inputCollapsed: false, custom: { display: 'hello' } });
assert.ok(obj !== newObj);
const sameObj = newObj.with({ inputCollapsed: false });
assert.ok(newObj === sameObj);
assert.strictEqual(obj.inputCollapsed, true);
assert.strictEqual(newObj.inputCollapsed, false);
assert.deepStrictEqual(newObj.custom, { display: 'hello' });
const newCustom = newObj.with({ anotherCustom: { display: 'hello2' } });
assert.strictEqual(newCustom.inputCollapsed, false);
assert.deepStrictEqual(newCustom.mycustom, undefined);
assert.deepStrictEqual(newCustom.anotherCustom, { display: 'hello2' });
});
});

View File

@@ -53,7 +53,12 @@ suite('ExtHostWebview', () => {
const serializerARegistration = extHostWebviewPanels.registerWebviewPanelSerializer(extension, viewType, serializerA);
await extHostWebviewPanels.$deserializeWebviewPanel('x', viewType, 'title', {}, 0 as EditorGroupColumn, {});
await extHostWebviewPanels.$deserializeWebviewPanel('x', viewType, {
title: 'title',
state: {},
panelOptions: {},
webviewOptions: {}
}, 0 as EditorGroupColumn);
assert.strictEqual(lastInvokedDeserializer, serializerA);
assert.throws(
@@ -64,7 +69,12 @@ suite('ExtHostWebview', () => {
extHostWebviewPanels.registerWebviewPanelSerializer(extension, viewType, serializerB);
await extHostWebviewPanels.$deserializeWebviewPanel('x', viewType, 'title', {}, 0 as EditorGroupColumn, {});
await extHostWebviewPanels.$deserializeWebviewPanel('x', viewType, {
title: 'title',
state: {},
panelOptions: {},
webviewOptions: {}
}, 0 as EditorGroupColumn);
assert.strictEqual(lastInvokedDeserializer, serializerB);
});

View File

@@ -28,10 +28,10 @@ function createExtHostWorkspace(mainContext: IMainContext, data: IWorkspaceData,
const result = new ExtHostWorkspace(
new ExtHostRpcService(mainContext),
new class extends mock<IExtHostInitDataService>() { workspace = data; },
new class extends mock<IExtHostFileSystemInfo>() { getCapabilities() { return isLinux ? FileSystemProviderCapabilities.PathCaseSensitive : undefined; } },
new class extends mock<IExtHostFileSystemInfo>() { override getCapabilities() { return isLinux ? FileSystemProviderCapabilities.PathCaseSensitive : undefined; } },
logService,
);
result.$initializeWorkspace(data);
result.$initializeWorkspace(data, true);
return result;
}
@@ -270,7 +270,7 @@ suite('ExtHostWorkspace', function () {
ws.$acceptWorkspaceData({ id: 'foo', name: 'Test', folders: [aWorkspaceFolderData(URI.parse('foo:bar3'), 0)] });
ws.$acceptWorkspaceData({ id: 'foo', name: 'Test', folders: [aWorkspaceFolderData(URI.parse('foo:bar3'), 0), aWorkspaceFolderData(URI.parse('foo:bar'), 1)] });
assert.notEqual(firstFolder, ws.workspace!.folders[0]);
assert.notStrictEqual(firstFolder, ws.workspace!.folders[0]);
});
test('updateWorkspaceFolders - invalid arguments', function () {
@@ -589,7 +589,7 @@ suite('ExtHostWorkspace', function () {
let mainThreadCalled = false;
rpcProtocol.set(MainContext.MainThreadWorkspace, new class extends mock<MainThreadWorkspace>() {
$startFileSearch(includePattern: string, _includeFolder: UriComponents | null, excludePatternOrDisregardExcludes: string | false, maxResults: number, token: CancellationToken): Promise<URI[] | null> {
override $startFileSearch(includePattern: string, _includeFolder: UriComponents | null, excludePatternOrDisregardExcludes: string | false, maxResults: number, token: CancellationToken): Promise<URI[] | null> {
mainThreadCalled = true;
assert.strictEqual(includePattern, 'foo');
assert.strictEqual(_includeFolder, null);
@@ -611,7 +611,7 @@ suite('ExtHostWorkspace', function () {
let mainThreadCalled = false;
rpcProtocol.set(MainContext.MainThreadWorkspace, new class extends mock<MainThreadWorkspace>() {
$startFileSearch(includePattern: string, _includeFolder: UriComponents | null, excludePatternOrDisregardExcludes: string | false, maxResults: number, token: CancellationToken): Promise<URI[] | null> {
override $startFileSearch(includePattern: string, _includeFolder: UriComponents | null, excludePatternOrDisregardExcludes: string | false, maxResults: number, token: CancellationToken): Promise<URI[] | null> {
mainThreadCalled = true;
assert.strictEqual(includePattern, 'glob/**');
assert.deepStrictEqual(_includeFolder ? URI.from(_includeFolder).toJSON() : null, URI.file('/other/folder').toJSON());
@@ -640,7 +640,7 @@ suite('ExtHostWorkspace', function () {
let mainThreadCalled = false;
rpcProtocol.set(MainContext.MainThreadWorkspace, new class extends mock<MainThreadWorkspace>() {
$startFileSearch(includePattern: string, _includeFolder: UriComponents | null, excludePatternOrDisregardExcludes: string | false, maxResults: number, token: CancellationToken): Promise<URI[] | null> {
override $startFileSearch(includePattern: string, _includeFolder: UriComponents | null, excludePatternOrDisregardExcludes: string | false, maxResults: number, token: CancellationToken): Promise<URI[] | null> {
mainThreadCalled = true;
assert.strictEqual(includePattern, 'glob/**');
assert.deepStrictEqual(_includeFolder, URI.file('/other/folder').toJSON());
@@ -661,7 +661,7 @@ suite('ExtHostWorkspace', function () {
let mainThreadCalled = false;
rpcProtocol.set(MainContext.MainThreadWorkspace, new class extends mock<MainThreadWorkspace>() {
$startFileSearch(includePattern: string, _includeFolder: UriComponents | null, excludePatternOrDisregardExcludes: string | false, maxResults: number, token: CancellationToken): Promise<URI[] | null> {
override $startFileSearch(includePattern: string, _includeFolder: UriComponents | null, excludePatternOrDisregardExcludes: string | false, maxResults: number, token: CancellationToken): Promise<URI[] | null> {
mainThreadCalled = true;
return Promise.resolve(null);
}
@@ -681,7 +681,7 @@ suite('ExtHostWorkspace', function () {
let mainThreadCalled = false;
rpcProtocol.set(MainContext.MainThreadWorkspace, new class extends mock<MainThreadWorkspace>() {
$startFileSearch(includePattern: string, _includeFolder: UriComponents | null, excludePatternOrDisregardExcludes: string | false, maxResults: number, token: CancellationToken): Promise<URI[] | null> {
override $startFileSearch(includePattern: string, _includeFolder: UriComponents | null, excludePatternOrDisregardExcludes: string | false, maxResults: number, token: CancellationToken): Promise<URI[] | null> {
mainThreadCalled = true;
assert(excludePatternOrDisregardExcludes, 'glob/**'); // Note that the base portion is ignored, see #52651
return Promise.resolve(null);
@@ -700,7 +700,7 @@ suite('ExtHostWorkspace', function () {
let mainThreadCalled = false;
rpcProtocol.set(MainContext.MainThreadWorkspace, new class extends mock<MainThreadWorkspace>() {
async $startTextSearch(query: IPatternInfo, folder: UriComponents | null, options: ITextQueryBuilderOptions, requestId: number, token: CancellationToken): Promise<ITextSearchComplete | null> {
override async $startTextSearch(query: IPatternInfo, folder: UriComponents | null, options: ITextQueryBuilderOptions, requestId: number, token: CancellationToken): Promise<ITextSearchComplete | null> {
mainThreadCalled = true;
assert.strictEqual(query.pattern, 'foo');
assert.strictEqual(folder, null);
@@ -721,7 +721,7 @@ suite('ExtHostWorkspace', function () {
let mainThreadCalled = false;
rpcProtocol.set(MainContext.MainThreadWorkspace, new class extends mock<MainThreadWorkspace>() {
async $startTextSearch(query: IPatternInfo, folder: UriComponents | null, options: ITextQueryBuilderOptions, requestId: number, token: CancellationToken): Promise<ITextSearchComplete | null> {
override async $startTextSearch(query: IPatternInfo, folder: UriComponents | null, options: ITextQueryBuilderOptions, requestId: number, token: CancellationToken): Promise<ITextSearchComplete | null> {
mainThreadCalled = true;
assert.strictEqual(query.pattern, 'foo');
assert.strictEqual(folder, null);
@@ -742,7 +742,7 @@ suite('ExtHostWorkspace', function () {
let mainThreadCalled = false;
rpcProtocol.set(MainContext.MainThreadWorkspace, new class extends mock<MainThreadWorkspace>() {
async $startTextSearch(query: IPatternInfo, folder: UriComponents | null, options: ITextQueryBuilderOptions, requestId: number, token: CancellationToken): Promise<ITextSearchComplete | null> {
override async $startTextSearch(query: IPatternInfo, folder: UriComponents | null, options: ITextQueryBuilderOptions, requestId: number, token: CancellationToken): Promise<ITextSearchComplete | null> {
mainThreadCalled = true;
assert.strictEqual(query.pattern, 'foo');
assert.deepStrictEqual(folder, URI.file('/other/folder').toJSON());
@@ -763,7 +763,7 @@ suite('ExtHostWorkspace', function () {
let mainThreadCalled = false;
rpcProtocol.set(MainContext.MainThreadWorkspace, new class extends mock<MainThreadWorkspace>() {
async $startTextSearch(query: IPatternInfo, folder: UriComponents | null, options: ITextQueryBuilderOptions, requestId: number, token: CancellationToken): Promise<ITextSearchComplete | null> {
override async $startTextSearch(query: IPatternInfo, folder: UriComponents | null, options: ITextQueryBuilderOptions, requestId: number, token: CancellationToken): Promise<ITextSearchComplete | null> {
mainThreadCalled = true;
return null;
}
@@ -781,7 +781,7 @@ suite('ExtHostWorkspace', function () {
let mainThreadCalled = false;
rpcProtocol.set(MainContext.MainThreadWorkspace, new class extends mock<MainThreadWorkspace>() {
async $startTextSearch(query: IPatternInfo, folder: UriComponents | null, options: ITextQueryBuilderOptions, requestId: number, token: CancellationToken): Promise<ITextSearchComplete | null> {
override async $startTextSearch(query: IPatternInfo, folder: UriComponents | null, options: ITextQueryBuilderOptions, requestId: number, token: CancellationToken): Promise<ITextSearchComplete | null> {
mainThreadCalled = true;
assert.strictEqual(query.pattern, 'foo');
assert.deepStrictEqual(folder, null);

View File

@@ -51,13 +51,13 @@ suite('MainThreadCommands', function () {
const commands = new MainThreadCommands(
SingleProxyRPCProtocol(null),
new class extends mock<ICommandService>() {
executeCommand<T>(id: string): Promise<T | undefined> {
override executeCommand<T>(id: string): Promise<T | undefined> {
runs.push(id);
return Promise.resolve(undefined);
}
},
new class extends mock<IExtensionService>() {
activateByEvent(id: string) {
override activateByEvent(id: string) {
activations.push(id);
return Promise.resolve();
}

View File

@@ -38,7 +38,7 @@ suite('MainThreadDiagnostics', function () {
},
markerService,
new class extends mock<IUriIdentityService>() {
asCanonicalUri(uri: URI) { return uri; }
override asCanonicalUri(uri: URI) { return uri; }
}
);

View File

@@ -22,13 +22,13 @@ suite('MainThreadDocumentContentProviders', function () {
let providers = new MainThreadDocumentContentProviders(new TestRPCProtocol(), null!, null!,
new class extends mock<IModelService>() {
getModel(_uri: URI) {
override getModel(_uri: URI) {
assert.strictEqual(uri.toString(), _uri.toString());
return model;
}
},
new class extends mock<IEditorWorkerService>() {
computeMoreMinimalEdits(_uri: URI, data: TextEdit[] | undefined) {
override computeMoreMinimalEdits(_uri: URI, data: TextEdit[] | undefined) {
assert.strictEqual(model.getValue(), '1');
return Promise.resolve(data);
}

View File

@@ -46,7 +46,7 @@ suite('BoundModelReferenceCollection', () => {
dispose() {
disposed.push(0);
}
});
}, 6);
col.add(
URI.parse('test://boofar'),
@@ -55,7 +55,7 @@ suite('BoundModelReferenceCollection', () => {
dispose() {
disposed.push(1);
}
});
}, 6);
col.add(
URI.parse('test://xxxxxxx'),
@@ -64,7 +64,7 @@ suite('BoundModelReferenceCollection', () => {
dispose() {
disposed.push(2);
}
});
}, 70);
assert.deepStrictEqual(disposed, [0, 1]);
});

View File

@@ -40,6 +40,7 @@ suite('MainThreadDocumentsAndEditors', () => {
function myCreateTestCodeEditor(model: ITextModel | undefined): ITestCodeEditor {
return createTestCodeEditor({
model: model,
hasTextFocus: false,
serviceCollection: new ServiceCollection(
[ICodeEditorService, codeEditorService]
)
@@ -56,8 +57,8 @@ suite('MainThreadDocumentsAndEditors', () => {
modelService = new ModelServiceImpl(configService, new TestTextResourcePropertiesService(configService), new TestThemeService(), new NullLogService(), undoRedoService);
codeEditorService = new TestCodeEditorService();
textFileService = new class extends mock<ITextFileService>() {
isDirty() { return false; }
files = <any>{
override isDirty() { return false; }
override files = <any>{
onDidSave: Event.None,
onDidRevert: Event.None,
onDidChangeDirty: Event.None
@@ -67,14 +68,14 @@ suite('MainThreadDocumentsAndEditors', () => {
const editorGroupService = new TestEditorGroupsService();
const fileService = new class extends mock<IFileService>() {
onDidRunOperation = Event.None;
onDidChangeFileSystemProviderCapabilities = Event.None;
onDidChangeFileSystemProviderRegistrations = Event.None;
override onDidRunOperation = Event.None;
override onDidChangeFileSystemProviderCapabilities = Event.None;
override onDidChangeFileSystemProviderRegistrations = Event.None;
};
new MainThreadDocumentsAndEditors(
SingleProxyRPCProtocol(new class extends mock<ExtHostDocumentsAndEditorsShape>() {
$acceptDocumentsAndEditorsDelta(delta: IDocumentsAndEditorsDelta) { deltas.push(delta); }
override $acceptDocumentsAndEditorsDelta(delta: IDocumentsAndEditorsDelta) { deltas.push(delta); }
}),
modelService,
textFileService,
@@ -85,10 +86,9 @@ suite('MainThreadDocumentsAndEditors', () => {
editorGroupService,
null!,
new class extends mock<IPanelService>() implements IPanelService {
declare readonly _serviceBrand: undefined;
onDidPanelOpen = Event.None;
onDidPanelClose = Event.None;
getActivePanel() {
override onDidPanelOpen = Event.None;
override onDidPanelClose = Event.None;
override getActivePanel() {
return undefined;
}
},
@@ -96,7 +96,7 @@ suite('MainThreadDocumentsAndEditors', () => {
new TestWorkingCopyFileService(),
new UriIdentityService(fileService),
new class extends mock<IClipboardService>() {
readText() {
override readText() {
return Promise.resolve('clipboard_contents');
}
},

View File

@@ -51,8 +51,8 @@ import { TestTextResourcePropertiesService, TestContextService } from 'vs/workbe
import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity';
import { extUri } from 'vs/base/common/resources';
import { ITextSnapshot } from 'vs/editor/common/model';
import { VSBuffer, VSBufferReadable } from 'vs/base/common/buffer';
import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
suite('MainThreadEditors', () => {
@@ -86,6 +86,7 @@ suite('MainThreadEditors', () => {
services.set(ILabelService, new SyncDescriptor(LabelService));
services.set(ILogService, new NullLogService());
services.set(IWorkspaceContextService, new TestContextService());
services.set(IEnvironmentService, TestEnvironmentService);
services.set(IWorkbenchEnvironmentService, TestEnvironmentService);
services.set(IConfigurationService, configService);
services.set(IDialogService, dialogService);
@@ -98,44 +99,44 @@ suite('MainThreadEditors', () => {
services.set(ILifecycleService, new TestLifecycleService());
services.set(IEditorGroupsService, new TestEditorGroupsService());
services.set(ITextFileService, new class extends mock<ITextFileService>() {
isDirty() { return false; }
files = <any>{
override isDirty() { return false; }
override files = <any>{
onDidSave: Event.None,
onDidRevert: Event.None,
onDidChangeDirty: Event.None
};
create(operations: { resource: URI }[]) {
override create(operations: { resource: URI }[]) {
for (const o of operations) {
createdResources.add(o.resource);
}
return Promise.resolve(Object.create(null));
}
async getEncodedReadable(resource: URI, value?: string | ITextSnapshot): Promise<VSBuffer | VSBufferReadable | undefined> {
override async getEncodedReadable(resource: URI, value?: string | ITextSnapshot): Promise<any> {
return undefined;
}
});
services.set(IWorkingCopyFileService, new class extends mock<IWorkingCopyFileService>() {
onDidRunWorkingCopyFileOperation = Event.None;
createFolder(operations: ICreateOperation[]): any {
override onDidRunWorkingCopyFileOperation = Event.None;
override createFolder(operations: ICreateOperation[]): any {
this.create(operations);
}
create(operations: ICreateFileOperation[]) {
override create(operations: ICreateFileOperation[]) {
for (const operation of operations) {
createdResources.add(operation.resource);
}
return Promise.resolve(Object.create(null));
}
move(operations: IMoveOperation[]) {
override move(operations: IMoveOperation[]) {
const { source, target } = operations[0].file;
movedResources.set(source, target);
return Promise.resolve(Object.create(null));
}
copy(operations: ICopyOperation[]) {
override copy(operations: ICopyOperation[]) {
const { source, target } = operations[0].file;
copiedResources.set(source, target);
return Promise.resolve(Object.create(null));
}
delete(operations: IDeleteOperation[]) {
override delete(operations: IDeleteOperation[]) {
for (const operation of operations) {
deletedResources.add(operation.resource);
}
@@ -143,9 +144,9 @@ suite('MainThreadEditors', () => {
}
});
services.set(ITextModelService, new class extends mock<ITextModelService>() {
createModelReference(resource: URI): Promise<IReference<IResolvedTextEditorModel>> {
override createModelReference(resource: URI): Promise<IReference<IResolvedTextEditorModel>> {
const textEditorModel = new class extends mock<IResolvedTextEditorModel>() {
textEditorModel = modelService.getModel(resource)!;
override textEditorModel = modelService.getModel(resource)!;
};
textEditorModel.isReadonly = () => false;
return Promise.resolve(new ImmortalReference(textEditorModel));
@@ -155,26 +156,25 @@ suite('MainThreadEditors', () => {
});
services.set(IPanelService, new class extends mock<IPanelService>() implements IPanelService {
declare readonly _serviceBrand: undefined;
onDidPanelOpen = Event.None;
onDidPanelClose = Event.None;
getActivePanel() {
override onDidPanelOpen = Event.None;
override onDidPanelClose = Event.None;
override getActivePanel() {
return undefined;
}
});
services.set(IUriIdentityService, new class extends mock<IUriIdentityService>() {
get extUri() { return extUri; }
override get extUri() { return extUri; }
});
const instaService = new InstantiationService(services);
const rpcProtocol = new TestRPCProtocol();
rpcProtocol.set(ExtHostContext.ExtHostDocuments, new class extends mock<ExtHostDocumentsShape>() {
$acceptModelChanged(): void {
override $acceptModelChanged(): void {
}
});
rpcProtocol.set(ExtHostContext.ExtHostDocumentsAndEditors, new class extends mock<ExtHostDocumentsAndEditorsShape>() {
$acceptDocumentsAndEditorsDelta(): void {
override $acceptDocumentsAndEditorsDelta(): void {
}
});

View File

@@ -29,15 +29,15 @@ suite('MainThreadHostTreeView', function () {
}
class MockExtHostTreeViewsShape extends mock<ExtHostTreeViewsShape>() {
async $getChildren(treeViewId: string, treeItemHandle?: string): Promise<ITreeItem[]> {
override async $getChildren(treeViewId: string, treeItemHandle?: string): Promise<ITreeItem[]> {
return [<CustomTreeItem>{ handle: 'testItem1', collapsibleState: TreeItemCollapsibleState.Expanded, customProp: customValue }];
}
async $hasResolve(): Promise<boolean> {
override async $hasResolve(): Promise<boolean> {
return false;
}
$setVisible(): void { }
override $setVisible(): void { }
}
let container: ViewContainer;