Skip to content

Commit

Permalink
[plugin] fix #4033: fix spreading of command arguments
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
  • Loading branch information
akosyakov committed Jan 16, 2019
1 parent 26e0392 commit e79109e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/api/plugin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export interface CommandRegistryMain {
$registerCommand(command: theia.Command): void;

$unregisterCommand(id: string): void;
$executeCommand<T>(id: string, args: any[]): PromiseLike<T | undefined>;
$executeCommand<T>(id: string, ...args: any[]): PromiseLike<T | undefined>;
$getCommands(): PromiseLike<string[]>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class CommandRegistryMainImpl implements CommandRegistryMain {
}
}
// tslint:disable-next-line:no-any
$executeCommand<T>(id: string, args: any[]): PromiseLike<T | undefined> {
$executeCommand<T>(id: string, ...args: any[]): PromiseLike<T | undefined> {
try {
return Promise.resolve(this.delegate.executeCommand(id, ...args));
} catch (e) {
Expand Down
12 changes: 6 additions & 6 deletions packages/plugin-ext/src/plugin/command-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,19 @@ export class CommandRegistryImpl implements CommandRegistryExt {
}

// tslint:disable-next-line:no-any
executeCommand<T>(id: string, args: any[]): PromiseLike<T | undefined> {
executeCommand<T>(id: string, ...args: any[]): PromiseLike<T | undefined> {
if (this.commands.has(id)) {
return this.executeLocalCommand(id, args);
return this.executeLocalCommand(id, ...args);
} else {
return this.proxy.$executeCommand(id, args);
return this.proxy.$executeCommand(id, ...args);
}
}

// tslint:disable-next-line:no-any
private executeLocalCommand<T>(id: string, args: any[]): PromiseLike<T> {
private executeLocalCommand<T>(id: string, ...args: any[]): PromiseLike<T> {
const handler = this.commands.get(id);
if (handler) {
return Promise.resolve(handler(args));
return Promise.resolve(handler(...args));
} else {
return Promise.reject(new Error(`Command ${id} doesn't exist`));
}
Expand Down Expand Up @@ -168,7 +168,7 @@ export class CommandsConverter {
if (!actualCmd) {
return Promise.resolve(undefined);
}
return this.commands.executeCommand(actualCmd.id, actualCmd.arguments || []);
return this.commands.executeCommand(actualCmd.id, ...(actualCmd.arguments || []));
}

/**
Expand Down
5 changes: 4 additions & 1 deletion packages/plugin-ext/src/plugin/node/debug/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,10 @@ export class DebugExtImpl implements DebugExt {
const contribution = this.debuggersContributions.get(type);
if (contribution) {
if (contribution.adapterExecutableCommand) {
return await this.commandRegistryExt.executeCommand(contribution.adapterExecutableCommand, []) as DebugAdapterExecutable;
const executable = await this.commandRegistryExt.executeCommand<DebugAdapterExecutable>(contribution.adapterExecutableCommand);
if (executable) {
return executable;
}
} else {
const contributionPath = this.contributionPaths.get(type);
if (contributionPath) {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export function createAPIFactory(
},
// tslint:disable-next-line:no-any
executeCommand<T>(commandId: string, ...args: any[]): PromiseLike<T | undefined> {
return commandRegistry.executeCommand<T>(commandId, args);
return commandRegistry.executeCommand<T>(commandId, ...args);
},
// tslint:disable-next-line:no-any
registerTextEditorCommand(command: theia.Command, callback: (textEditor: theia.TextEditor, edit: theia.TextEditorEdit, ...arg: any[]) => void): Disposable {
Expand Down
3 changes: 1 addition & 2 deletions packages/plugin-ext/src/plugin/tree/tree-views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ class TreeViewExtImpl<T> extends Disposable {
const treeItem = await this.treeDataProvider.getTreeItem(cachedElement);

if (treeItem.command) {
this.commandRegistry.executeCommand(treeItem.command.id, treeItem.command.arguments ?
treeItem.command.arguments : []);
this.commandRegistry.executeCommand(treeItem.command.id, ...(treeItem.command.arguments || []));
}
}
}
Expand Down

0 comments on commit e79109e

Please sign in to comment.