From e79109e41279663295f0e11903bb1228035d5890 Mon Sep 17 00:00:00 2001 From: Anton Kosyakov Date: Fri, 11 Jan 2019 16:08:52 +0000 Subject: [PATCH] [plugin] fix #4033: fix spreading of command arguments Signed-off-by: Anton Kosyakov --- packages/plugin-ext/src/api/plugin-api.ts | 2 +- .../src/main/browser/command-registry-main.ts | 2 +- packages/plugin-ext/src/plugin/command-registry.ts | 12 ++++++------ packages/plugin-ext/src/plugin/node/debug/debug.ts | 5 ++++- packages/plugin-ext/src/plugin/plugin-context.ts | 2 +- packages/plugin-ext/src/plugin/tree/tree-views.ts | 3 +-- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/plugin-ext/src/api/plugin-api.ts b/packages/plugin-ext/src/api/plugin-api.ts index 626cfee436e11..d94b56f9e1024 100644 --- a/packages/plugin-ext/src/api/plugin-api.ts +++ b/packages/plugin-ext/src/api/plugin-api.ts @@ -153,7 +153,7 @@ export interface CommandRegistryMain { $registerCommand(command: theia.Command): void; $unregisterCommand(id: string): void; - $executeCommand(id: string, args: any[]): PromiseLike; + $executeCommand(id: string, ...args: any[]): PromiseLike; $getCommands(): PromiseLike; } diff --git a/packages/plugin-ext/src/main/browser/command-registry-main.ts b/packages/plugin-ext/src/main/browser/command-registry-main.ts index 9c9102e6a4c13..10cc73963c61a 100644 --- a/packages/plugin-ext/src/main/browser/command-registry-main.ts +++ b/packages/plugin-ext/src/main/browser/command-registry-main.ts @@ -53,7 +53,7 @@ export class CommandRegistryMainImpl implements CommandRegistryMain { } } // tslint:disable-next-line:no-any - $executeCommand(id: string, args: any[]): PromiseLike { + $executeCommand(id: string, ...args: any[]): PromiseLike { try { return Promise.resolve(this.delegate.executeCommand(id, ...args)); } catch (e) { diff --git a/packages/plugin-ext/src/plugin/command-registry.ts b/packages/plugin-ext/src/plugin/command-registry.ts index d7c3f1c7100d7..4ee4a726c1510 100644 --- a/packages/plugin-ext/src/plugin/command-registry.ts +++ b/packages/plugin-ext/src/plugin/command-registry.ts @@ -87,19 +87,19 @@ export class CommandRegistryImpl implements CommandRegistryExt { } // tslint:disable-next-line:no-any - executeCommand(id: string, args: any[]): PromiseLike { + executeCommand(id: string, ...args: any[]): PromiseLike { 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(id: string, args: any[]): PromiseLike { + private executeLocalCommand(id: string, ...args: any[]): PromiseLike { 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`)); } @@ -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 || [])); } /** diff --git a/packages/plugin-ext/src/plugin/node/debug/debug.ts b/packages/plugin-ext/src/plugin/node/debug/debug.ts index 103110c3105cb..d7a5760ddb333 100644 --- a/packages/plugin-ext/src/plugin/node/debug/debug.ts +++ b/packages/plugin-ext/src/plugin/node/debug/debug.ts @@ -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(contribution.adapterExecutableCommand); + if (executable) { + return executable; + } } else { const contributionPath = this.contributionPaths.get(type); if (contributionPath) { diff --git a/packages/plugin-ext/src/plugin/plugin-context.ts b/packages/plugin-ext/src/plugin/plugin-context.ts index 4b3ec7bbfa2b8..afd89fdffa1ef 100644 --- a/packages/plugin-ext/src/plugin/plugin-context.ts +++ b/packages/plugin-ext/src/plugin/plugin-context.ts @@ -155,7 +155,7 @@ export function createAPIFactory( }, // tslint:disable-next-line:no-any executeCommand(commandId: string, ...args: any[]): PromiseLike { - return commandRegistry.executeCommand(commandId, args); + return commandRegistry.executeCommand(commandId, ...args); }, // tslint:disable-next-line:no-any registerTextEditorCommand(command: theia.Command, callback: (textEditor: theia.TextEditor, edit: theia.TextEditorEdit, ...arg: any[]) => void): Disposable { diff --git a/packages/plugin-ext/src/plugin/tree/tree-views.ts b/packages/plugin-ext/src/plugin/tree/tree-views.ts index cf6fca9a7a547..96aca5b9b4c00 100644 --- a/packages/plugin-ext/src/plugin/tree/tree-views.ts +++ b/packages/plugin-ext/src/plugin/tree/tree-views.ts @@ -263,8 +263,7 @@ class TreeViewExtImpl 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 || [])); } } }