diff --git a/src/vs/base/common/marshalling.ts b/src/vs/base/common/marshalling.ts index 7536ec5210dd1cfaa34d55f43c799c1fcc6d4092..9275b413307c6746eb527f7f7376caad4085b355 100644 --- a/src/vs/base/common/marshalling.ts +++ b/src/vs/base/common/marshalling.ts @@ -30,9 +30,6 @@ function replacer(key: string, value: any): any { return value; } -// TODO@Joao hack? -export const ResolverRegistry: { [mid: number]: (value: any) => any; } = Object.create(null); - function reviver(key: string, value: any): any { let marshallingConst: number; if (value !== void 0 && value !== null) { @@ -42,13 +39,6 @@ function reviver(key: string, value: any): any { switch (marshallingConst) { case 1: return URI.revive(value); case 2: return new RegExp(value.source, value.flags); - default: - const resolver = ResolverRegistry[marshallingConst]; - - if (resolver) { - return resolver(value); - } else { - return value; - } + default: return value; } } diff --git a/src/vs/workbench/api/node/extHostCommands.ts b/src/vs/workbench/api/node/extHostCommands.ts index e8ebf85b36fdd120ba19d6483643a50398d52f88..6f99ac35fe8b23809ab8e53b38c499929b253fb3 100644 --- a/src/vs/workbench/api/node/extHostCommands.ts +++ b/src/vs/workbench/api/node/extHostCommands.ts @@ -23,11 +23,16 @@ interface CommandHandler { description: ICommandHandlerDescription; } +export interface ArgumentProcessor { + processArgument(arg: any): any; +} + export class ExtHostCommands extends ExtHostCommandsShape { private _commands = new Map(); private _proxy: MainThreadCommandsShape; private _converter: CommandsConverter; + private _argumentProcessors: ArgumentProcessor[] = []; constructor( threadService: IThreadService, @@ -42,6 +47,10 @@ export class ExtHostCommands extends ExtHostCommandsShape { return this._converter; } + registerArgumentProcessor(processor: ArgumentProcessor): void { + this._argumentProcessors.push(processor); + } + registerCommand(id: string, callback: (...args: any[]) => T | Thenable, thisArg?: any, description?: ICommandHandlerDescription): extHostTypes.Disposable { if (!id.trim().length) { @@ -110,6 +119,8 @@ export class ExtHostCommands extends ExtHostCommandsShape { } } + args = args.map(arg => this._argumentProcessors.reduce((r, p) => p.processArgument(r), arg)); + try { let result = callback.apply(thisArg, args); return TPromise.as(result); diff --git a/src/vs/workbench/api/node/extHostSCM.ts b/src/vs/workbench/api/node/extHostSCM.ts index 92f855c0f65577600eb0f9a63b8945f53369a59e..84b6e8c8ef94eba0a66806ce50c6cee1d24b0367 100644 --- a/src/vs/workbench/api/node/extHostSCM.ts +++ b/src/vs/workbench/api/node/extHostSCM.ts @@ -12,7 +12,6 @@ import { IThreadService } from 'vs/workbench/services/thread/common/threadServic import { ExtHostCommands, CommandsConverter } from 'vs/workbench/api/node/extHostCommands'; import { MainContext, MainThreadSCMShape, SCMRawResource } from './extHost.protocol'; import * as vscode from 'vscode'; -import * as marshalling from 'vs/base/common/marshalling'; function getIconPath(decorations: vscode.SourceControlResourceThemableDecorations) { if (!decorations) { @@ -241,16 +240,21 @@ export class ExtHostSCM { this._proxy = threadService.get(MainContext.MainThreadSCM); this._inputBox = new ExtHostSCMInputBox(this._proxy); - // TODO@joao HACK - marshalling.ResolverRegistry[3] = value => { - const sourceControl = this._sourceControls.get(value.sourceControlHandle); + _commands.registerArgumentProcessor({ + processArgument: arg => { + if (arg && arg.$mid === 3) { + const sourceControl = this._sourceControls.get(arg.sourceControlHandle); - if (!sourceControl) { - return value; - } + if (!sourceControl) { + return arg; + } + + return sourceControl.getResourceState(arg.groupHandle, arg.handle); + } - return sourceControl.getResourceState(value.groupHandle, value.handle); - }; + return arg; + } + }); } createSourceControl(id: string, label: string): vscode.SourceControl {