mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-21 09:08:53 +01:00
Revert "fix https://github.com/microsoft/vscode/issues/150293 (#151616)" (#152026)
This reverts commit 670c3fd002.
This commit is contained in:
@@ -60,7 +60,7 @@ suite('ExtHostCommands', function () {
|
||||
assert.strictEqual(unregisterCounter, 1);
|
||||
});
|
||||
|
||||
test('execute triggers activate', async function () {
|
||||
test('execute with retry', async function () {
|
||||
|
||||
let count = 0;
|
||||
|
||||
@@ -68,13 +68,16 @@ suite('ExtHostCommands', function () {
|
||||
override $registerCommand(id: string): void {
|
||||
//
|
||||
}
|
||||
|
||||
override async $activateByCommandEvent(id: string): Promise<void> {
|
||||
count += 1;
|
||||
}
|
||||
|
||||
override async $executeCommand<T>(id: string, args: any[]): Promise<T | undefined> {
|
||||
return undefined;
|
||||
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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -83,7 +86,8 @@ suite('ExtHostCommands', function () {
|
||||
new NullLogService()
|
||||
);
|
||||
|
||||
await commands.executeCommand('fooo', [this, true]);
|
||||
assert.strictEqual(count, 1);
|
||||
const result = await commands.executeCommand('fooo', [this, true]);
|
||||
assert.strictEqual(result, 17);
|
||||
assert.strictEqual(count, 2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import * as assert from 'assert';
|
||||
import { MainThreadCommands } from 'vs/workbench/api/browser/mainThreadCommands';
|
||||
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
|
||||
import { CommandsRegistry, ICommandService } 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,4 +42,46 @@ 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']);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user