Merge branch 'main' into joh/voluminous-lobster

This commit is contained in:
Johannes
2022-06-10 09:07:30 +02:00
115 changed files with 2137 additions and 1993 deletions

View File

@@ -60,7 +60,7 @@ suite('ExtHostCommands', function () {
assert.strictEqual(unregisterCounter, 1);
});
test('execute with retry', async function () {
test('execute triggers activate', async function () {
let count = 0;
@@ -68,16 +68,13 @@ suite('ExtHostCommands', function () {
override $registerCommand(id: string): void {
//
}
override async $executeCommand<T>(id: string, args: any[], retry: boolean): Promise<T | undefined> {
count++;
assert.strictEqual(retry, count === 1);
if (count === 1) {
assert.strictEqual(retry, true);
throw new Error('$executeCommand:retry');
} else {
assert.strictEqual(retry, false);
return <any>17;
}
override async $activateByCommandEvent(id: string): Promise<void> {
count += 1;
}
override async $executeCommand<T>(id: string, args: any[]): Promise<T | undefined> {
return undefined;
}
};
@@ -86,8 +83,7 @@ suite('ExtHostCommands', function () {
new NullLogService()
);
const result = await commands.executeCommand('fooo', [this, true]);
assert.strictEqual(result, 17);
assert.strictEqual(count, 2);
await commands.executeCommand('fooo', [this, true]);
assert.strictEqual(count, 1);
});
});

View File

@@ -5,7 +5,7 @@
import * as assert from 'assert';
import { MainThreadCommands } from 'vs/workbench/api/browser/mainThreadCommands';
import { CommandsRegistry, ICommandService } from 'vs/platform/commands/common/commands';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { SingleProxyRPCProtocol } from 'vs/workbench/api/test/common/testRPCProtocol';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { mock } from 'vs/base/test/common/mock';
@@ -42,46 +42,4 @@ suite('MainThreadCommands', function () {
assert.strictEqual(CommandsRegistry.getCommand('foo'), undefined);
assert.strictEqual(CommandsRegistry.getCommand('bar'), undefined);
});
test('activate and throw when needed', async function () {
const activations: string[] = [];
const runs: string[] = [];
const commands = new MainThreadCommands(
SingleProxyRPCProtocol(null),
new class extends mock<ICommandService>() {
override executeCommand<T>(id: string): Promise<T | undefined> {
runs.push(id);
return Promise.resolve(undefined);
}
},
new class extends mock<IExtensionService>() {
override activateByEvent(id: string) {
activations.push(id);
return Promise.resolve();
}
}
);
// case 1: arguments and retry
try {
activations.length = 0;
await commands.$executeCommand('bazz', [1, 2, { n: 3 }], true);
assert.ok(false);
} catch (e) {
assert.deepStrictEqual(activations, ['onCommand:bazz']);
assert.strictEqual((<Error>e).message, '$executeCommand:retry');
}
// case 2: no arguments and retry
runs.length = 0;
await commands.$executeCommand('bazz', [], true);
assert.deepStrictEqual(runs, ['bazz']);
// case 3: arguments and no retry
runs.length = 0;
await commands.$executeCommand('bazz', [1, 2, true], false);
assert.deepStrictEqual(runs, ['bazz']);
});
});

View File

@@ -57,9 +57,7 @@ export class TestRPCProtocol implements IExtHostContext, IExtHostRpcService {
private set _callCount(value: number) {
this._callCountValue = value;
if (this._callCountValue === 0) {
if (this._completeIdle) {
this._completeIdle();
}
this._completeIdle?.();
this._idle = undefined;
}
}