Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Nov 2, 2017
1 parent b4d7531 commit c8a8fc7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
18 changes: 17 additions & 1 deletion extensions/vscode-api-tests/src/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ suite('commands namespace tests', () => {
});
});

test('command with return-value', function () {

let registration = commands.registerCommand('t1', function () {
return new Set<number>().add(1).add(2);
});

return commands.executeCommand('t1', 'start').then(value => {
registration.dispose();

assert.ok(value instanceof Set);
assert.equal((<Set<number>>value).size, 2);
assert.equal((<Set<number>>value).has(1), true);
assert.equal((<Set<number>>value).has(2), true);
});
});

test('editorCommand with extra args', function () {

let args: IArguments;
Expand Down Expand Up @@ -134,4 +150,4 @@ suite('commands namespace tests', () => {

return Promise.all([a, b, c, d]);
});
});
});
2 changes: 1 addition & 1 deletion src/vs/workbench/api/node/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ export interface MainThreadWindowShape extends IDisposable {
// -- extension host

export interface ExtHostCommandsShape {
$executeContributedCommand<T>(id: string, ...args: any[]): Thenable<T>;
$executeContributedCommand<T>(id: string, ...args: any[]): Thenable<void>;
$getContributedCommandHandlerDescriptions(): TPromise<{ [id: string]: string | ICommandHandlerDescription }>;
}

Expand Down
9 changes: 6 additions & 3 deletions src/vs/workbench/api/node/extHostCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(id, ...args);
return this._executeContributedCommand<T>(id, ...args);

} else {
// automagically convert some argument types
Expand All @@ -96,10 +96,9 @@ export class ExtHostCommands implements ExtHostCommandsShape {

return this._proxy.$executeCommand<T>(id, args);
}

}

$executeContributedCommand<T>(id: string, ...args: any[]): Thenable<T> {
private _executeContributedCommand<T>(id: string, ...args: any[]): Thenable<T> {
let command = this._commands.get(id);
if (!command) {
return TPromise.wrapError<T>(new Error(`Contributed command '${id}' does not exist.`));
Expand Down Expand Up @@ -133,6 +132,10 @@ export class ExtHostCommands implements ExtHostCommandsShape {
}
}

$executeContributedCommand<T>(id: string, ...args: any[]): Thenable<void> {
return this._executeContributedCommand(id, ...args).then(result => void 0);
}

getCommands(filterUnderscoreCommands: boolean = false): Thenable<string[]> {
return this._proxy.$getCommands().then(result => {
if (filterUnderscoreCommands) {
Expand Down

0 comments on commit c8a8fc7

Please sign in to comment.