mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 02:58:56 +01:00
scm api: getOriginalResource
This commit is contained in:
@@ -229,6 +229,8 @@ export abstract class MainProcessExtensionServiceShape {
|
||||
}
|
||||
|
||||
export abstract class MainThreadSCMShape {
|
||||
$register(id: string, registerOriginalResourceProvider: boolean): void { throw ni(); }
|
||||
$unregister(id: string): void { throw ni(); }
|
||||
}
|
||||
|
||||
// -- extension host
|
||||
@@ -359,6 +361,7 @@ export abstract class ExtHostTerminalServiceShape {
|
||||
}
|
||||
|
||||
export abstract class ExtHostSCMShape {
|
||||
$getBaselineResource(id: string, uri: URI): TPromise<URI> { throw ni(); }
|
||||
}
|
||||
|
||||
// --- proxy identifiers
|
||||
@@ -382,7 +385,7 @@ export const MainContext = {
|
||||
MainThreadTerminalService: createMainId<MainThreadTerminalServiceShape>('MainThreadTerminalService', MainThreadTerminalServiceShape),
|
||||
MainThreadWorkspace: createMainId<MainThreadWorkspaceShape>('MainThreadWorkspace', MainThreadWorkspaceShape),
|
||||
MainProcessExtensionService: createMainId<MainProcessExtensionServiceShape>('MainProcessExtensionService', MainProcessExtensionServiceShape),
|
||||
MainThreadSCM: createMainId('MainThreadSCM', MainThreadSCMShape)
|
||||
MainThreadSCM: createMainId<MainThreadSCMShape>('MainThreadSCM', MainThreadSCMShape)
|
||||
};
|
||||
|
||||
export const ExtHostContext = {
|
||||
|
||||
@@ -4,31 +4,45 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { asWinJsPromise } from 'vs/base/common/async';
|
||||
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
|
||||
import { SCMProvider, SCMDelegate, SCMResourceGroup } from 'vscode';
|
||||
import { MainContext, MainThreadSCMShape } from './extHost.protocol';
|
||||
|
||||
export class ExtHostSCMProvider implements SCMProvider {
|
||||
class ExtHostSCMProvider implements SCMProvider {
|
||||
|
||||
private static ID_GEN = 0;
|
||||
private _id: number = ExtHostSCMProvider.ID_GEN++;
|
||||
static Providers: { [id: string]: ExtHostSCMProvider; } = Object.create(null);
|
||||
|
||||
constructor(
|
||||
private _proxy: MainThreadSCMShape,
|
||||
private _id: string,
|
||||
private _delegate: SCMDelegate
|
||||
) { }
|
||||
) {
|
||||
if (ExtHostSCMProvider.Providers[_id]) {
|
||||
throw new Error('provider already exists');
|
||||
}
|
||||
|
||||
get id(): number {
|
||||
ExtHostSCMProvider.Providers[_id] = this;
|
||||
_proxy.$register(this._id, !!this._delegate.getOriginalResource);
|
||||
}
|
||||
|
||||
get id(): string {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
createResourceGroup(id: string, label: string): SCMResourceGroup {
|
||||
// throw new Error('JOAO not implemented');
|
||||
return null;
|
||||
throw new Error('JOAO not implemented');
|
||||
}
|
||||
|
||||
getBaselineResource(uri: URI): TPromise<URI> {
|
||||
return asWinJsPromise(token => this._delegate.getOriginalResource(uri, token));
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
// todo
|
||||
this._proxy.$unregister(this._id);
|
||||
delete ExtHostSCMProvider.Providers[this.id];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +54,17 @@ export class ExtHostSCM {
|
||||
this._proxy = threadService.get(MainContext.MainThreadSCM);
|
||||
}
|
||||
|
||||
createSCMProvider(id: string, delegate: SCMDelegate): ExtHostSCMProvider {
|
||||
return new ExtHostSCMProvider(this._proxy, delegate);
|
||||
createSCMProvider(id: string, delegate: SCMDelegate): SCMProvider {
|
||||
return new ExtHostSCMProvider(this._proxy, id, delegate);
|
||||
}
|
||||
|
||||
$getBaselineResource(id: string, uri: URI): TPromise<URI> {
|
||||
const provider = ExtHostSCMProvider.Providers[id];
|
||||
|
||||
if (!provider) {
|
||||
return TPromise.as(null);
|
||||
}
|
||||
|
||||
return provider.getBaselineResource(uri);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,22 +4,52 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { IDisposable, dispose, combinedDisposable } from 'vs/base/common/lifecycle';
|
||||
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
|
||||
import { MainThreadSCMShape } from './extHost.protocol';
|
||||
import { ISCMService } from 'vs/workbench/services/scm/common/scm';
|
||||
import { ExtHostContext, MainThreadSCMShape, ExtHostSCMShape } from './extHost.protocol';
|
||||
|
||||
export class MainThreadSCM extends MainThreadSCMShape {
|
||||
|
||||
private _toDispose: IDisposable;
|
||||
private toDispose: IDisposable;
|
||||
private proxy: ExtHostSCMShape;
|
||||
private providers: { [id: string]: IDisposable; } = Object.create(null);
|
||||
|
||||
constructor(
|
||||
@IThreadService threadService: IThreadService
|
||||
@IThreadService threadService: IThreadService,
|
||||
@ISCMService private scmService: ISCMService
|
||||
) {
|
||||
super();
|
||||
// const proxy = threadService.get(ExtHostContext.ExtHostSCM);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
$unregister(id: string): void {
|
||||
const provider = this.providers[id];
|
||||
|
||||
if (!provider) {
|
||||
return;
|
||||
}
|
||||
|
||||
provider.dispose();
|
||||
delete this.providers[id];
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this._toDispose = dispose(this._toDispose);
|
||||
this.toDispose = dispose(this.toDispose);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user