From c8a8fc7ddd03005a9b59d53deabff1ae4f699dc7 Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Thu, 2 Nov 2017 11:04:49 +0100 Subject: [PATCH] fix #37484 --- .../vscode-api-tests/src/commands.test.ts | 18 +++++++++++++++++- src/vs/workbench/api/node/extHost.protocol.ts | 2 +- src/vs/workbench/api/node/extHostCommands.ts | 9 ++++++--- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/extensions/vscode-api-tests/src/commands.test.ts b/extensions/vscode-api-tests/src/commands.test.ts index 0d92795d241..28d727bc1ca 100644 --- a/extensions/vscode-api-tests/src/commands.test.ts +++ b/extensions/vscode-api-tests/src/commands.test.ts @@ -56,6 +56,22 @@ suite('commands namespace tests', () => { }); }); + test('command with return-value', function () { + + let registration = commands.registerCommand('t1', function () { + return new Set().add(1).add(2); + }); + + return commands.executeCommand('t1', 'start').then(value => { + registration.dispose(); + + assert.ok(value instanceof Set); + assert.equal((>value).size, 2); + assert.equal((>value).has(1), true); + assert.equal((>value).has(2), true); + }); + }); + test('editorCommand with extra args', function () { let args: IArguments; @@ -134,4 +150,4 @@ suite('commands namespace tests', () => { return Promise.all([a, b, c, d]); }); -}); \ No newline at end of file +}); diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index ea75a41995c..89e8011b409 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -429,7 +429,7 @@ export interface MainThreadWindowShape extends IDisposable { // -- extension host export interface ExtHostCommandsShape { - $executeContributedCommand(id: string, ...args: any[]): Thenable; + $executeContributedCommand(id: string, ...args: any[]): Thenable; $getContributedCommandHandlerDescriptions(): TPromise<{ [id: string]: string | ICommandHandlerDescription }>; } diff --git a/src/vs/workbench/api/node/extHostCommands.ts b/src/vs/workbench/api/node/extHostCommands.ts index 774d71f8e26..ca82afcef48 100644 --- a/src/vs/workbench/api/node/extHostCommands.ts +++ b/src/vs/workbench/api/node/extHostCommands.ts @@ -74,7 +74,7 @@ export class ExtHostCommands implements ExtHostCommandsShape { if (this._commands.has(id)) { // we stay inside the extension host and support // to pass any kind of parameters around - return this.$executeContributedCommand(id, ...args); + return this._executeContributedCommand(id, ...args); } else { // automagically convert some argument types @@ -96,10 +96,9 @@ export class ExtHostCommands implements ExtHostCommandsShape { return this._proxy.$executeCommand(id, args); } - } - $executeContributedCommand(id: string, ...args: any[]): Thenable { + private _executeContributedCommand(id: string, ...args: any[]): Thenable { let command = this._commands.get(id); if (!command) { return TPromise.wrapError(new Error(`Contributed command '${id}' does not exist.`)); @@ -133,6 +132,10 @@ export class ExtHostCommands implements ExtHostCommandsShape { } } + $executeContributedCommand(id: string, ...args: any[]): Thenable { + return this._executeContributedCommand(id, ...args).then(result => void 0); + } + getCommands(filterUnderscoreCommands: boolean = false): Thenable { return this._proxy.$getCommands().then(result => { if (filterUnderscoreCommands) {