mirror of
https://github.com/microsoft/vscode.git
synced 2026-03-01 06:06:04 +00:00
MainThreadSCMProvider
This commit is contained in:
@@ -4,38 +4,77 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { IDisposable, dispose, combinedDisposable } from 'vs/base/common/lifecycle';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import Event from 'vs/base/common/event';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
|
||||
import { ISCMService } from 'vs/workbench/services/scm/common/scm';
|
||||
import { ISCMService, ISCMProvider, ISCMResourceGroup, ISCMResource } from 'vs/workbench/services/scm/common/scm';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { ExtHostContext, MainThreadSCMShape, ExtHostSCMShape } from './extHost.protocol';
|
||||
|
||||
interface Supports {
|
||||
originalResource: boolean;
|
||||
}
|
||||
|
||||
class MainThreadSCMProvider implements ISCMProvider {
|
||||
|
||||
get id(): string { return this._id; }
|
||||
readonly onChange: Event<void>;
|
||||
readonly resourceGroups: ISCMResourceGroup[] = [];
|
||||
private disposables: IDisposable[] = [];
|
||||
|
||||
constructor(
|
||||
private _id: string,
|
||||
private proxy: ExtHostSCMShape,
|
||||
private supports: Supports,
|
||||
@ISCMService scmService: ISCMService
|
||||
) {
|
||||
this.disposables.push(scmService.registerSCMProvider(this));
|
||||
}
|
||||
|
||||
commit(message: string): TPromise<void> {
|
||||
return TPromise.wrapError<void>('commit not implemented');
|
||||
}
|
||||
|
||||
open(uri: ISCMResource): TPromise<void> {
|
||||
return TPromise.wrapError<void>('open not implemented');
|
||||
}
|
||||
|
||||
drag(from: ISCMResource, to: ISCMResource): TPromise<void> {
|
||||
return TPromise.wrapError<void>('drag not implemented');
|
||||
}
|
||||
|
||||
getOriginalResource(uri: URI): TPromise<URI> {
|
||||
if (!this.supports.originalResource) {
|
||||
return TPromise.as(null);
|
||||
}
|
||||
|
||||
return this.proxy.$getBaselineResource(this.id, uri);
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.disposables = dispose(this.disposables);
|
||||
}
|
||||
}
|
||||
|
||||
export class MainThreadSCM extends MainThreadSCMShape {
|
||||
|
||||
private toDispose: IDisposable;
|
||||
private proxy: ExtHostSCMShape;
|
||||
private providers: { [id: string]: IDisposable; } = Object.create(null);
|
||||
|
||||
constructor(
|
||||
@IThreadService threadService: IThreadService,
|
||||
@ISCMService private scmService: ISCMService
|
||||
@IInstantiationService private instantiationService: IInstantiationService
|
||||
) {
|
||||
super();
|
||||
|
||||
this.proxy = threadService.get(ExtHostContext.ExtHostSCM);
|
||||
}
|
||||
|
||||
$register(id: string, registerOriginalResourceProvider: boolean): void {
|
||||
const disposables = [];
|
||||
|
||||
if (registerOriginalResourceProvider) {
|
||||
const baselineProvider = this.scmService.registerBaselineResourceProvider({
|
||||
getBaselineResource: uri => this.proxy.$getBaselineResource(id, uri)
|
||||
});
|
||||
|
||||
disposables.push(baselineProvider);
|
||||
}
|
||||
|
||||
this.providers[id] = combinedDisposable(disposables);
|
||||
this.providers[id] = this.instantiationService.createInstance(MainThreadSCMProvider, id, this.proxy, {
|
||||
originalResource: registerOriginalResourceProvider
|
||||
});
|
||||
}
|
||||
|
||||
$unregister(id: string): void {
|
||||
@@ -50,6 +89,9 @@ export class MainThreadSCM extends MainThreadSCMShape {
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.toDispose = dispose(this.toDispose);
|
||||
Object.keys(this.providers)
|
||||
.forEach(id => this.providers[id].dispose());
|
||||
|
||||
this.providers = Object.create(null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user