diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 930889dba15..f10d6f271b9 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -289,7 +289,7 @@ export abstract class ExtHostEditorsShape { export abstract class ExtHostTreeExplorersShape { $provideRootNode(providerId: string): TPromise { throw ni(); }; $resolveChildren(providerId: string, node: InternalTreeExplorerNode): TPromise { throw ni(); } - $executeCommand(providerId: string, node: InternalTreeExplorerNode): TPromise { throw ni(); } + $getInternalCommand(providerId: string, node: InternalTreeExplorerNode): TPromise { throw ni(); } } export abstract class ExtHostExtensionServiceShape { diff --git a/src/vs/workbench/api/node/extHostTreeExplorers.ts b/src/vs/workbench/api/node/extHostTreeExplorers.ts index 4659b8f7acf..11d88c548ee 100644 --- a/src/vs/workbench/api/node/extHostTreeExplorers.ts +++ b/src/vs/workbench/api/node/extHostTreeExplorers.ts @@ -12,6 +12,7 @@ import { MainContext, ExtHostTreeExplorersShape, MainThreadTreeExplorersShape } import { InternalTreeExplorerNode } from 'vs/workbench/parts/explorers/common/treeExplorerViewModel'; import { ExtHostCommands } from 'vs/workbench/api/node/extHostCommands'; import { asWinJsPromise } from 'vs/base/common/async'; +import * as modes from 'vs/editor/common/modes'; export class ExtHostTreeExplorers extends ExtHostTreeExplorersShape { private _proxy: MainThreadTreeExplorersShape; @@ -79,14 +80,20 @@ export class ExtHostTreeExplorers extends ExtHostTreeExplorersShape { }); } - $executeCommand(providerId: string, mainThreadNode: InternalTreeExplorerNode): TPromise { + // Convert the command on the ExtHost side so we can pass the original externalNode to the registered handler + $getInternalCommand(providerId: string, mainThreadNode: InternalTreeExplorerNode): TPromise { + const commandConverter = this.commands.converter; + if (mainThreadNode.clickCommand) { const externalNode = this._externalNodeMaps[providerId][mainThreadNode.id]; - return asWinJsPromise(() => this.commands.executeCommand(mainThreadNode.clickCommand, externalNode)).then(() => { - return null; - }, err => { - return TPromise.wrapError(`Failed to execute command '${mainThreadNode.clickCommand}' provided by TreeExplorerNodeProvider '${providerId}'.`); + + const internalCommand = commandConverter.toInternal({ + title: '', + command: mainThreadNode.clickCommand, + arguments: [externalNode] }); + + return TPromise.wrap(internalCommand); } return TPromise.as(null); diff --git a/src/vs/workbench/api/node/mainThreadTreeExplorers.ts b/src/vs/workbench/api/node/mainThreadTreeExplorers.ts index 54ac3c368c2..985fa31c84a 100644 --- a/src/vs/workbench/api/node/mainThreadTreeExplorers.ts +++ b/src/vs/workbench/api/node/mainThreadTreeExplorers.ts @@ -10,6 +10,7 @@ import { ExtHostContext, MainThreadTreeExplorersShape, ExtHostTreeExplorersShape import { ITreeExplorerViewletService } from 'vs/workbench/parts/explorers/browser/treeExplorerViewletService'; import { InternalTreeExplorerNode } from 'vs/workbench/parts/explorers/common/treeExplorerViewModel'; import { IMessageService, Severity } from 'vs/platform/message/common/message'; +import { ICommandService } from 'vs/platform/commands/common/commands'; export class MainThreadTreeExplorers extends MainThreadTreeExplorersShape { private _proxy: ExtHostTreeExplorersShape; @@ -17,7 +18,8 @@ export class MainThreadTreeExplorers extends MainThreadTreeExplorersShape { constructor( @IThreadService private threadService: IThreadService, @ITreeExplorerViewletService private treeExplorerService: ITreeExplorerViewletService, - @IMessageService private messageService: IMessageService + @IMessageService private messageService: IMessageService, + @ICommandService private commandService: ICommandService ) { super(); @@ -34,8 +36,10 @@ export class MainThreadTreeExplorers extends MainThreadTreeExplorersShape { resolveChildren: (node: InternalTreeExplorerNode): TPromise => { return this._proxy.$resolveChildren(providerId, node).then(children => children, onError); }, - executeCommand: (node: InternalTreeExplorerNode): TPromise => { - return this._proxy.$executeCommand(providerId, node); + executeCommand: (node: InternalTreeExplorerNode): TPromise => { + return this._proxy.$getInternalCommand(providerId, node).then(command => { + return this.commandService.executeCommand(command.id, ...command.arguments); + }); } }); } diff --git a/src/vs/workbench/parts/explorers/browser/treeExplorerViewletService.ts b/src/vs/workbench/parts/explorers/browser/treeExplorerViewletService.ts index 531c7185d38..b126224d7f7 100644 --- a/src/vs/workbench/parts/explorers/browser/treeExplorerViewletService.ts +++ b/src/vs/workbench/parts/explorers/browser/treeExplorerViewletService.ts @@ -59,7 +59,7 @@ export class TreeExplorerViewletService implements ITreeExplorerViewletService { return TPromise.wrap(provider.resolveChildren(node)); } - public executeCommand(providerId: string, node: InternalTreeExplorerNode): TPromise { + public executeCommand(providerId: string, node: InternalTreeExplorerNode): TPromise { const provider = this.getProvider(providerId); return TPromise.wrap(provider.executeCommand(node)); } diff --git a/src/vs/workbench/parts/explorers/common/treeExplorerViewModel.ts b/src/vs/workbench/parts/explorers/common/treeExplorerViewModel.ts index e86f91d4510..a61a951fef7 100644 --- a/src/vs/workbench/parts/explorers/common/treeExplorerViewModel.ts +++ b/src/vs/workbench/parts/explorers/common/treeExplorerViewModel.ts @@ -28,7 +28,7 @@ export class InternalTreeExplorerNode implements TreeExplorerNodeContent { export interface InternalTreeExplorerNodeProvider { provideRootNode(): Thenable; resolveChildren(node: InternalTreeExplorerNode): Thenable; - executeCommand(node: TreeExplorerNodeContent): TPromise; + executeCommand(node: TreeExplorerNodeContent): TPromise; } export interface TreeExplorerNodeContent {