diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 55b5cd38ee5..3ba69934e18 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -420,6 +420,7 @@ export abstract class ExtHostTerminalServiceShape { export abstract class ExtHostSCMShape { $open(handle: number, uri: string): TPromise { throw ni(); } $getOriginalResource(handle: number, uri: URI): TPromise { throw ni(); } + $onActiveProviderChange(handle: number): TPromise { throw ni(); } $onInputBoxValueChange(value: string): TPromise { throw ni(); } $onInputBoxAcceptChanges(): TPromise { throw ni(); } } diff --git a/src/vs/workbench/api/node/extHostSCM.ts b/src/vs/workbench/api/node/extHostSCM.ts index 99ffa751f55..b6c0220018e 100644 --- a/src/vs/workbench/api/node/extHostSCM.ts +++ b/src/vs/workbench/api/node/extHostSCM.ts @@ -80,7 +80,7 @@ export class ExtHostSCM { private _onDidChangeActiveProvider = new Emitter(); get onDidChangeActiveProvider(): Event { return this._onDidChangeActiveProvider.event; } - private _activeProvider: vscode.SCMProvider; + private _activeProvider: vscode.SCMProvider | undefined; get activeProvider(): vscode.SCMProvider | undefined { return this._activeProvider; } private _inputBox: ExtHostSCMInputBox; @@ -178,6 +178,11 @@ export class ExtHostSCM { return asWinJsPromise(token => provider.provideOriginalResource(uri, token)); } + $onActiveProviderChange(handle: number): TPromise { + this._activeProvider = this._providers.get(handle); + return TPromise.as(null); + } + $onInputBoxValueChange(value: string): TPromise { this._inputBox.$onInputBoxValueChange(value); return TPromise.as(null); diff --git a/src/vs/workbench/api/node/mainThreadSCM.ts b/src/vs/workbench/api/node/mainThreadSCM.ts index 931aa083c95..608e598a3a4 100644 --- a/src/vs/workbench/api/node/mainThreadSCM.ts +++ b/src/vs/workbench/api/node/mainThreadSCM.ts @@ -43,7 +43,6 @@ class MainThreadSCMProvider implements ISCMProvider { @ICommandService private commandService: ICommandService ) { scmService.onDidChangeProvider(this.onDidChangeProvider, this, this.disposables); - this.disposables.push(scmService.registerSCMProvider(this)); } open(resource: ISCMResource): void { @@ -111,7 +110,9 @@ export class MainThreadSCM extends MainThreadSCMShape { private proxy: ExtHostSCMShape; private providers: { [handle: number]: MainThreadSCMProvider; } = Object.create(null); - private inputBoxListeners: IDisposable[] = []; + private providerDisposables: { [handle: number]: IDisposable; } = Object.create(null); + + private disposables: IDisposable[] = []; constructor( @IThreadService threadService: IThreadService, @@ -121,12 +122,15 @@ export class MainThreadSCM extends MainThreadSCMShape { super(); this.proxy = threadService.get(ExtHostContext.ExtHostSCM); - this.scmService.input.onDidChange(this.proxy.$onInputBoxValueChange, this.proxy, this.inputBoxListeners); - this.scmService.input.onDidAccept(this.proxy.$onInputBoxAcceptChanges, this.proxy, this.inputBoxListeners); + this.scmService.onDidChangeProvider(this.onDidChangeProvider, this, this.disposables); + this.scmService.input.onDidChange(this.proxy.$onInputBoxValueChange, this.proxy, this.disposables); + this.scmService.input.onDidAccept(this.proxy.$onInputBoxAcceptChanges, this.proxy, this.disposables); } $register(handle: number, features: SCMProviderFeatures): void { - this.providers[handle] = this.instantiationService.createInstance(MainThreadSCMProvider, handle, this.proxy, features); + const provider = this.instantiationService.createInstance(MainThreadSCMProvider, handle, this.proxy, features); + this.providers[handle] = provider; + this.providerDisposables[handle] = this.scmService.registerSCMProvider(provider); } $unregister(handle: number): void { @@ -136,6 +140,9 @@ export class MainThreadSCM extends MainThreadSCMShape { return; } + this.providerDisposables[handle].dispose(); + delete this.providerDisposables[handle]; + provider.dispose(); delete this.providers[handle]; } @@ -154,11 +161,16 @@ export class MainThreadSCM extends MainThreadSCMShape { this.scmService.input.value = value; } + private onDidChangeProvider(provider: ISCMProvider): void { + const handle = Object.keys(this.providers).filter(handle => this.providers[handle] === provider)[0]; + this.proxy.$onActiveProviderChange(handle && parseInt(handle)); + } + dispose(): void { Object.keys(this.providers) .forEach(id => this.providers[id].dispose()); this.providers = Object.create(null); - this.inputBoxListeners = dispose(this.inputBoxListeners); + this.disposables = dispose(this.disposables); } }