mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-25 19:18:59 +01:00
scm: move from pull to push model
This commit is contained in:
@@ -117,7 +117,7 @@ export function createApiFactory(
|
||||
const extHostFileSystemEvent = col.define(ExtHostContext.ExtHostFileSystemEventService).set<ExtHostFileSystemEventService>(new ExtHostFileSystemEventService());
|
||||
const extHostQuickOpen = col.define(ExtHostContext.ExtHostQuickOpen).set<ExtHostQuickOpen>(new ExtHostQuickOpen(threadService));
|
||||
const extHostTerminalService = col.define(ExtHostContext.ExtHostTerminalService).set<ExtHostTerminalService>(new ExtHostTerminalService(threadService));
|
||||
const extHostSCM = col.define(ExtHostContext.ExtHostSCM).set<ExtHostSCM>(new ExtHostSCM(threadService));
|
||||
const extHostSCM = col.define(ExtHostContext.ExtHostSCM).set<ExtHostSCM>(new ExtHostSCM(threadService, extHostCommands));
|
||||
const extHostTask = col.define(ExtHostContext.ExtHostTask).set<ExtHostTask>(new ExtHostTask(threadService));
|
||||
col.define(ExtHostContext.ExtHostExtensionService).set(extensionService);
|
||||
col.finish(false, threadService);
|
||||
@@ -448,30 +448,30 @@ export function createApiFactory(
|
||||
|
||||
class SCM {
|
||||
|
||||
get activeProvider() {
|
||||
get activeSourceControl() {
|
||||
return extHostSCM.activeProvider;
|
||||
}
|
||||
|
||||
get onDidChangeActiveProvider() {
|
||||
get onDidChangeActiveSourceControl() {
|
||||
return extHostSCM.onDidChangeActiveProvider;
|
||||
}
|
||||
|
||||
get onDidAcceptInputValue() {
|
||||
return mapEvent(extHostSCM.inputBox.onDidAccept, () => extHostSCM.inputBox);
|
||||
}
|
||||
|
||||
get inputBox() {
|
||||
return extHostSCM.inputBox;
|
||||
}
|
||||
|
||||
registerSCMProvider(provider: vscode.SCMProvider) {
|
||||
get onDidAcceptInputValue() {
|
||||
return mapEvent(extHostSCM.inputBox.onDidAccept, () => extHostSCM.inputBox);
|
||||
}
|
||||
|
||||
createSourceControl(id: string, label: string) {
|
||||
telemetryService.publicLog('registerSCMProvider', {
|
||||
extensionId: extension.id,
|
||||
providerLabel: provider.label,
|
||||
providerContextKey: provider.contextKey
|
||||
providerId: id,
|
||||
providerLabel: label
|
||||
});
|
||||
|
||||
return extHostSCM.registerSCMProvider(provider);
|
||||
return extHostSCM.createSourceControl(id, label);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -251,30 +251,31 @@ export abstract class MainProcessExtensionServiceShape {
|
||||
}
|
||||
|
||||
export interface SCMProviderFeatures {
|
||||
label: string;
|
||||
contextKey?: string;
|
||||
supportsOpen: boolean;
|
||||
supportsOriginalResource: boolean;
|
||||
hasQuickDiffProvider?: boolean;
|
||||
count?: number;
|
||||
}
|
||||
|
||||
export interface SCMGroupFeatures {
|
||||
hideWhenEmpty?: boolean;
|
||||
}
|
||||
|
||||
export type SCMRawResource = [
|
||||
string /*uri*/,
|
||||
string /*sourceUri*/,
|
||||
string /*resourceUri*/,
|
||||
modes.Command /*command*/,
|
||||
string[] /*icons: light, dark*/,
|
||||
boolean /*strike through*/
|
||||
];
|
||||
|
||||
export type SCMRawResourceGroup = [
|
||||
string /*uri*/,
|
||||
string | undefined /*context key*/,
|
||||
string /*label*/,
|
||||
SCMRawResource[]
|
||||
];
|
||||
|
||||
export abstract class MainThreadSCMShape {
|
||||
$register(handle: number, features: SCMProviderFeatures): void { throw ni(); }
|
||||
$unregister(handle: number): void { throw ni(); }
|
||||
$onChange(handle: number, resources: SCMRawResourceGroup[], count: number | undefined, stateContextKey: string | undefined): void { throw ni(); }
|
||||
$registerSourceControl(handle: number, id: string, label: string): void { throw ni(); }
|
||||
$updateSourceControl(handle: number, features: SCMProviderFeatures): void { throw ni(); }
|
||||
$unregisterSourceControl(handle: number): void { throw ni(); }
|
||||
|
||||
$registerGroup(sourceControlHandle: number, handle: number, id: string, label: string): void { throw ni(); }
|
||||
$updateGroup(sourceControlHandle: number, handle: number, features: SCMGroupFeatures): void { throw ni(); }
|
||||
$updateGroupResourceStates(sourceControlHandle: number, groupHandle: number, resources: SCMRawResource[]): void { throw ni(); }
|
||||
$unregisterGroup(sourceControlHandle: number, handle: number): void { throw ni(); }
|
||||
|
||||
$setInputBoxValue(value: string): void { throw ni(); }
|
||||
}
|
||||
|
||||
@@ -418,9 +419,8 @@ export abstract class ExtHostTerminalServiceShape {
|
||||
}
|
||||
|
||||
export abstract class ExtHostSCMShape {
|
||||
$open(handle: number, uri: string): TPromise<void> { throw ni(); }
|
||||
$getOriginalResource(handle: number, uri: URI): TPromise<URI> { throw ni(); }
|
||||
$onActiveProviderChange(handle: number): TPromise<void> { throw ni(); }
|
||||
$provideOriginalResource(sourceControlHandle: number, uri: URI): TPromise<URI> { throw ni(); }
|
||||
$onActiveSourceControlChange(sourceControlHandle: number): TPromise<void> { throw ni(); }
|
||||
$onInputBoxValueChange(value: string): TPromise<void> { throw ni(); }
|
||||
$onInputBoxAcceptChanges(): TPromise<void> { throw ni(); }
|
||||
}
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import Event, { Emitter, debounceEvent, createEmptyEvent } from 'vs/base/common/event';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { asWinJsPromise } from 'vs/base/common/async';
|
||||
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
|
||||
import { Disposable } from 'vs/workbench/api/node/extHostTypes';
|
||||
import { MainContext, MainThreadSCMShape, SCMRawResource, SCMRawResourceGroup } from './extHost.protocol';
|
||||
import { ExtHostCommands, CommandsConverter } from 'vs/workbench/api/node/extHostCommands';
|
||||
import { MainContext, MainThreadSCMShape, SCMRawResource } from './extHost.protocol';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
function getIconPath(decorations: vscode.SCMResourceThemableDecorations) {
|
||||
function getIconPath(decorations: vscode.SourceControlResourceThemableDecorations) {
|
||||
if (!decorations) {
|
||||
return undefined;
|
||||
} else if (typeof decorations.iconPath === 'string') {
|
||||
@@ -67,6 +67,133 @@ export class ExtHostSCMInputBox {
|
||||
}
|
||||
}
|
||||
|
||||
class ExtHostSourceControlResourceGroup implements vscode.SourceControlResourceGroup {
|
||||
|
||||
private static _handlePool: number = 0;
|
||||
|
||||
get id(): string {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
get label(): string {
|
||||
return this._label;
|
||||
}
|
||||
|
||||
private _hideWhenEmpty: boolean | undefined = undefined;
|
||||
|
||||
get hideWhenEmpty(): boolean | undefined {
|
||||
return this._hideWhenEmpty;
|
||||
}
|
||||
|
||||
set hideWhenEmpty(hideWhenEmpty: boolean | undefined) {
|
||||
this._hideWhenEmpty = hideWhenEmpty;
|
||||
this._proxy.$updateGroup(this._sourceControlHandle, this._handle, { hideWhenEmpty });
|
||||
}
|
||||
|
||||
private _resourcesStates: vscode.SourceControlResourceState[] = [];
|
||||
|
||||
get resourceStates(): vscode.SourceControlResourceState[] {
|
||||
return this._resourcesStates;
|
||||
}
|
||||
|
||||
set resourceStates(resources: vscode.SourceControlResourceState[]) {
|
||||
this._resourcesStates = resources;
|
||||
|
||||
const rawResources = resources.map(r => {
|
||||
const sourceUri = r.resourceUri.toString();
|
||||
const command = this._commands.toInternal(r.command);
|
||||
const iconPath = getIconPath(r.decorations);
|
||||
const lightIconPath = r.decorations && getIconPath(r.decorations.light) || iconPath;
|
||||
const darkIconPath = r.decorations && getIconPath(r.decorations.dark) || iconPath;
|
||||
const icons: string[] = [];
|
||||
|
||||
if (lightIconPath || darkIconPath) {
|
||||
icons.push(lightIconPath);
|
||||
}
|
||||
|
||||
if (darkIconPath !== lightIconPath) {
|
||||
icons.push(darkIconPath);
|
||||
}
|
||||
|
||||
const strikeThrough = r.decorations && !!r.decorations.strikeThrough;
|
||||
|
||||
return [sourceUri, command, icons, strikeThrough] as SCMRawResource;
|
||||
});
|
||||
|
||||
this._proxy.$updateGroupResourceStates(this._sourceControlHandle, this._handle, rawResources);
|
||||
}
|
||||
|
||||
private _handle: number = ExtHostSourceControlResourceGroup._handlePool++;
|
||||
|
||||
constructor(
|
||||
private _proxy: MainThreadSCMShape,
|
||||
private _commands: CommandsConverter,
|
||||
private _sourceControlHandle: number,
|
||||
private _id: string,
|
||||
private _label: string,
|
||||
) {
|
||||
this._proxy.$registerGroup(_sourceControlHandle, this._handle, _id, _label);
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this._proxy.$unregisterGroup(this._sourceControlHandle, this._handle);
|
||||
}
|
||||
}
|
||||
|
||||
class ExtHostSourceControl implements vscode.SourceControl {
|
||||
|
||||
private static _handlePool: number = 0;
|
||||
|
||||
get id(): string {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
get label(): string {
|
||||
return this._label;
|
||||
}
|
||||
|
||||
private _count: number | undefined = undefined;
|
||||
|
||||
get count(): number | undefined {
|
||||
return this._count;
|
||||
}
|
||||
|
||||
set count(count: number | undefined) {
|
||||
this._count = count;
|
||||
this._proxy.$updateSourceControl(this._handle, { count });
|
||||
}
|
||||
|
||||
private _quickDiffProvider: vscode.QuickDiffProvider | undefined = undefined;
|
||||
|
||||
get quickDiffProvider(): vscode.QuickDiffProvider | undefined {
|
||||
return this._quickDiffProvider;
|
||||
}
|
||||
|
||||
set quickDiffProvider(quickDiffProvider: vscode.QuickDiffProvider | undefined) {
|
||||
this._quickDiffProvider = quickDiffProvider;
|
||||
this._proxy.$updateSourceControl(this._handle, { hasQuickDiffProvider: !!quickDiffProvider });
|
||||
}
|
||||
|
||||
private _handle: number = ExtHostSourceControl._handlePool++;
|
||||
|
||||
constructor(
|
||||
private _proxy: MainThreadSCMShape,
|
||||
private _commands: CommandsConverter,
|
||||
private _id: string,
|
||||
private _label: string,
|
||||
) {
|
||||
this._proxy.$registerSourceControl(this._handle, _id, _label);
|
||||
}
|
||||
|
||||
createResourceGroup(id: string, label: string): ExtHostSourceControlResourceGroup {
|
||||
return new ExtHostSourceControlResourceGroup(this._proxy, this._commands, this._handle, id, label);
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this._proxy.$unregisterSourceControl(this._handle);
|
||||
}
|
||||
}
|
||||
|
||||
type ProviderHandle = number;
|
||||
|
||||
export class ExtHostSCM {
|
||||
@@ -74,112 +201,45 @@ export class ExtHostSCM {
|
||||
private static _handlePool: number = 0;
|
||||
|
||||
private _proxy: MainThreadSCMShape;
|
||||
private _providers: Map<ProviderHandle, vscode.SCMProvider> = new Map<ProviderHandle, vscode.SCMProvider>();
|
||||
private _cache: Map<ProviderHandle, Map<string, vscode.SCMResource>> = new Map<ProviderHandle, Map<string, vscode.SCMResource>>();
|
||||
private _sourceControls: Map<ProviderHandle, vscode.SourceControl> = new Map<ProviderHandle, vscode.SourceControl>();
|
||||
|
||||
private _onDidChangeActiveProvider = new Emitter<vscode.SCMProvider>();
|
||||
get onDidChangeActiveProvider(): Event<vscode.SCMProvider> { return this._onDidChangeActiveProvider.event; }
|
||||
private _onDidChangeActiveProvider = new Emitter<vscode.SourceControl>();
|
||||
get onDidChangeActiveProvider(): Event<vscode.SourceControl> { return this._onDidChangeActiveProvider.event; }
|
||||
|
||||
private _activeProvider: vscode.SCMProvider | undefined;
|
||||
get activeProvider(): vscode.SCMProvider | undefined { return this._activeProvider; }
|
||||
private _activeProvider: vscode.SourceControl | undefined;
|
||||
get activeProvider(): vscode.SourceControl | undefined { return this._activeProvider; }
|
||||
|
||||
private _inputBox: ExtHostSCMInputBox;
|
||||
get inputBox(): ExtHostSCMInputBox { return this._inputBox; }
|
||||
|
||||
constructor(threadService: IThreadService) {
|
||||
constructor(
|
||||
threadService: IThreadService,
|
||||
private _commands: ExtHostCommands
|
||||
) {
|
||||
this._proxy = threadService.get(MainContext.MainThreadSCM);
|
||||
this._inputBox = new ExtHostSCMInputBox(this._proxy);
|
||||
}
|
||||
|
||||
registerSCMProvider(provider: vscode.SCMProvider): Disposable {
|
||||
createSourceControl(id: string, label: string): vscode.SourceControl {
|
||||
const handle = ExtHostSCM._handlePool++;
|
||||
const sourceControl = new ExtHostSourceControl(this._proxy, this._commands.converter, id, label);
|
||||
this._sourceControls.set(handle, sourceControl);
|
||||
|
||||
this._providers.set(handle, provider);
|
||||
|
||||
this._proxy.$register(handle, {
|
||||
label: provider.label,
|
||||
contextKey: provider.contextKey,
|
||||
supportsOpen: !!provider.open,
|
||||
supportsOriginalResource: !!provider.provideOriginalResource
|
||||
});
|
||||
|
||||
const onDidChange = debounceEvent(provider.onDidChange || createEmptyEvent<vscode.SCMProvider>(), (l, e) => e, 100);
|
||||
const onDidChangeListener = onDidChange(scmProvider => {
|
||||
const cache = new Map<string, vscode.SCMResource>();
|
||||
this._cache.set(handle, cache);
|
||||
|
||||
const rawResourceGroups = scmProvider.resources.map(g => {
|
||||
const rawResources = g.resources.map(r => {
|
||||
const uri = r.uri.toString();
|
||||
cache.set(uri, r);
|
||||
|
||||
const sourceUri = r.sourceUri.toString();
|
||||
const iconPath = getIconPath(r.decorations);
|
||||
const lightIconPath = r.decorations && getIconPath(r.decorations.light) || iconPath;
|
||||
const darkIconPath = r.decorations && getIconPath(r.decorations.dark) || iconPath;
|
||||
const icons: string[] = [];
|
||||
|
||||
if (lightIconPath || darkIconPath) {
|
||||
icons.push(lightIconPath);
|
||||
}
|
||||
|
||||
if (darkIconPath !== lightIconPath) {
|
||||
icons.push(darkIconPath);
|
||||
}
|
||||
|
||||
const strikeThrough = r.decorations && !!r.decorations.strikeThrough;
|
||||
|
||||
return [uri, sourceUri, icons, strikeThrough] as SCMRawResource;
|
||||
});
|
||||
|
||||
return [g.uri.toString(), g.contextKey, g.label, rawResources] as SCMRawResourceGroup;
|
||||
});
|
||||
|
||||
this._proxy.$onChange(handle, rawResourceGroups, provider.count, provider.stateContextKey);
|
||||
});
|
||||
|
||||
return new Disposable(() => {
|
||||
onDidChangeListener.dispose();
|
||||
this._providers.delete(handle);
|
||||
this._proxy.$unregister(handle);
|
||||
});
|
||||
return sourceControl;
|
||||
}
|
||||
|
||||
$open(handle: number, uri: string): TPromise<void> {
|
||||
const provider = this._providers.get(handle);
|
||||
$provideOriginalResource(sourceControlHandle: number, uri: URI): TPromise<URI> {
|
||||
const sourceControl = this._sourceControls.get(sourceControlHandle);
|
||||
|
||||
if (!provider) {
|
||||
if (!sourceControl || !sourceControl.quickDiffProvider) {
|
||||
return TPromise.as(null);
|
||||
}
|
||||
|
||||
const cache = this._cache.get(handle);
|
||||
|
||||
if (!cache) {
|
||||
return TPromise.as(null);
|
||||
}
|
||||
|
||||
const resource = cache.get(uri);
|
||||
|
||||
if (!resource) {
|
||||
return TPromise.as(null);
|
||||
}
|
||||
|
||||
provider.open(resource);
|
||||
return TPromise.as(null);
|
||||
return asWinJsPromise(token => sourceControl.quickDiffProvider.provideOriginalResource(uri, token));
|
||||
}
|
||||
|
||||
$getOriginalResource(handle: number, uri: URI): TPromise<URI> {
|
||||
const provider = this._providers.get(handle);
|
||||
|
||||
if (!provider) {
|
||||
return TPromise.as(null);
|
||||
}
|
||||
|
||||
return asWinJsPromise(token => provider.provideOriginalResource(uri, token));
|
||||
}
|
||||
|
||||
$onActiveProviderChange(handle: number): TPromise<void> {
|
||||
this._activeProvider = this._providers.get(handle);
|
||||
$onActiveSourceControlChange(handle: number): TPromise<void> {
|
||||
this._activeProvider = this._sourceControls.get(handle);
|
||||
return TPromise.as(null);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,154 +7,223 @@
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { assign } from 'vs/base/common/objects';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
|
||||
import { ISCMService, ISCMProvider, ISCMResource, ISCMResourceGroup } from 'vs/workbench/services/scm/common/scm';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||
import { ExtHostContext, MainThreadSCMShape, ExtHostSCMShape, SCMProviderFeatures, SCMRawResourceGroup } from './extHost.protocol';
|
||||
import { ExtHostContext, MainThreadSCMShape, ExtHostSCMShape, SCMProviderFeatures, SCMRawResource, SCMGroupFeatures } from './extHost.protocol';
|
||||
|
||||
interface IMainThreadSCMResourceGroup {
|
||||
uri: URI;
|
||||
features: SCMGroupFeatures;
|
||||
label: string;
|
||||
contextKey?: string;
|
||||
resources: ISCMResource[];
|
||||
}
|
||||
|
||||
class MainThreadSCMProvider implements ISCMProvider {
|
||||
|
||||
private _resources: ISCMResourceGroup[] = [];
|
||||
get resources(): ISCMResourceGroup[] { return this._resources; }
|
||||
private _groups: IMainThreadSCMResourceGroup[] = [];
|
||||
private _groupsByHandle: { [handle: number]: IMainThreadSCMResourceGroup; } = Object.create(null);
|
||||
|
||||
private _onDidChange = new Emitter<ISCMResourceGroup[]>();
|
||||
get onDidChange(): Event<ISCMResourceGroup[]> { return this._onDidChange.event; }
|
||||
get resources(): ISCMResourceGroup[] {
|
||||
return this._groups
|
||||
.filter(g => g.resources.length > 0 || !g.features.hideWhenEmpty);
|
||||
}
|
||||
|
||||
private disposables: IDisposable[] = [];
|
||||
private _onDidChange = new Emitter<void>();
|
||||
get onDidChange(): Event<void> { return this._onDidChange.event; }
|
||||
|
||||
private features: SCMProviderFeatures = {};
|
||||
|
||||
get handle(): number { return this._handle; }
|
||||
get label(): string { return this.features.label; }
|
||||
get contextKey(): string { return this.features.contextKey; }
|
||||
get label(): string { return this._label; }
|
||||
get contextKey(): string { return this._id; }
|
||||
|
||||
private _count: number | undefined = undefined;
|
||||
get count(): number | undefined { return this._count; }
|
||||
|
||||
private _stateContextKey: string | undefined = undefined;
|
||||
get stateContextKey(): string | undefined { return this._stateContextKey; }
|
||||
|
||||
constructor(
|
||||
private _handle: number,
|
||||
private proxy: ExtHostSCMShape,
|
||||
private features: SCMProviderFeatures,
|
||||
private _handle: number,
|
||||
private _id: string,
|
||||
private _label: string,
|
||||
@ISCMService scmService: ISCMService,
|
||||
@ICommandService private commandService: ICommandService
|
||||
) {
|
||||
scmService.onDidChangeProvider(this.onDidChangeProvider, this, this.disposables);
|
||||
) { }
|
||||
|
||||
$updateSourceControl(features: SCMProviderFeatures): void {
|
||||
this.features = assign(this.features, features);
|
||||
this._onDidChange.fire();
|
||||
}
|
||||
|
||||
open(resource: ISCMResource): void {
|
||||
if (!this.features.supportsOpen) {
|
||||
$registerGroup(handle: number, id: string, label: string): void {
|
||||
const group: IMainThreadSCMResourceGroup = {
|
||||
contextKey: id,
|
||||
label,
|
||||
uri: null,
|
||||
resources: [],
|
||||
features: {}
|
||||
};
|
||||
|
||||
this._groups.push(group);
|
||||
this._groupsByHandle[handle] = group;
|
||||
}
|
||||
|
||||
$updateGroup(handle: number, features: SCMGroupFeatures): void {
|
||||
const group = this._groupsByHandle[handle];
|
||||
|
||||
if (!group) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.proxy.$open(this.handle, resource.uri.toString())
|
||||
.done(null, onUnexpectedError);
|
||||
group.features = assign(group.features, features);
|
||||
this._onDidChange.fire();
|
||||
}
|
||||
|
||||
$updateGroupResourceStates(handle: number, resources: SCMRawResource[]): void {
|
||||
const group = this._groupsByHandle[handle];
|
||||
|
||||
if (!group) {
|
||||
return;
|
||||
}
|
||||
|
||||
group.resources = resources.map(rawResource => {
|
||||
const [sourceUri, command, icons, strikeThrough] = rawResource;
|
||||
const icon = icons[0];
|
||||
const iconDark = icons[1] || icon;
|
||||
const decorations = {
|
||||
icon: icon && URI.parse(icon),
|
||||
iconDark: iconDark && URI.parse(iconDark),
|
||||
strikeThrough
|
||||
};
|
||||
|
||||
return {
|
||||
sourceUri: URI.parse(sourceUri),
|
||||
command,
|
||||
resourceGroup: group,
|
||||
decorations
|
||||
};
|
||||
});
|
||||
|
||||
this._onDidChange.fire();
|
||||
}
|
||||
|
||||
$unregisterGroup(handle: number): void {
|
||||
const group = this._groupsByHandle[handle];
|
||||
|
||||
if (!group) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete this._groupsByHandle[handle];
|
||||
this._groups.splice(this._groups.indexOf(group), 1);
|
||||
}
|
||||
|
||||
getOriginalResource(uri: URI): TPromise<URI> {
|
||||
if (!this.features.supportsOriginalResource) {
|
||||
if (!this.features.hasQuickDiffProvider) {
|
||||
return TPromise.as(null);
|
||||
}
|
||||
|
||||
return this.proxy.$getOriginalResource(this.handle, uri);
|
||||
}
|
||||
|
||||
private onDidChangeProvider(provider: ISCMProvider): void {
|
||||
// if (provider === this) {
|
||||
// return
|
||||
// }
|
||||
}
|
||||
|
||||
$onChange(rawResourceGroups: SCMRawResourceGroup[], count: number | undefined, stateContextKey: string | undefined): void {
|
||||
this._resources = rawResourceGroups.map(rawGroup => {
|
||||
const [uri, contextKey, label, rawResources] = rawGroup;
|
||||
const resources: ISCMResource[] = [];
|
||||
const group: ISCMResourceGroup = { uri: URI.parse(uri), contextKey, label, resources };
|
||||
|
||||
rawResources.forEach(rawResource => {
|
||||
const [uri, sourceUri, icons, strikeThrough] = rawResource;
|
||||
const icon = icons[0];
|
||||
const iconDark = icons[1] || icon;
|
||||
const decorations = {
|
||||
icon: icon && URI.parse(icon),
|
||||
iconDark: iconDark && URI.parse(iconDark),
|
||||
strikeThrough
|
||||
};
|
||||
|
||||
resources.push({
|
||||
resourceGroup: group,
|
||||
uri: URI.parse(uri),
|
||||
sourceUri: URI.parse(sourceUri),
|
||||
decorations
|
||||
});
|
||||
});
|
||||
|
||||
return group;
|
||||
});
|
||||
|
||||
this._count = count;
|
||||
this._stateContextKey = stateContextKey;
|
||||
|
||||
this._onDidChange.fire(this.resources);
|
||||
return this.proxy.$provideOriginalResource(this.handle, uri);
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.disposables = dispose(this.disposables);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export class MainThreadSCM extends MainThreadSCMShape {
|
||||
|
||||
private proxy: ExtHostSCMShape;
|
||||
private providers: { [handle: number]: MainThreadSCMProvider; } = Object.create(null);
|
||||
private providerDisposables: { [handle: number]: IDisposable; } = Object.create(null);
|
||||
|
||||
private disposables: IDisposable[] = [];
|
||||
private _proxy: ExtHostSCMShape;
|
||||
private _sourceControls: { [handle: number]: MainThreadSCMProvider; } = Object.create(null);
|
||||
private _sourceControlDisposables: { [handle: number]: IDisposable; } = Object.create(null);
|
||||
private _disposables: IDisposable[] = [];
|
||||
|
||||
constructor(
|
||||
@IThreadService threadService: IThreadService,
|
||||
@IInstantiationService private instantiationService: IInstantiationService,
|
||||
@ISCMService private scmService: ISCMService
|
||||
@ISCMService private scmService: ISCMService,
|
||||
@ICommandService private commandService: ICommandService
|
||||
) {
|
||||
super();
|
||||
this.proxy = threadService.get(ExtHostContext.ExtHostSCM);
|
||||
this._proxy = threadService.get(ExtHostContext.ExtHostSCM);
|
||||
|
||||
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);
|
||||
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 {
|
||||
const provider = this.instantiationService.createInstance(MainThreadSCMProvider, handle, this.proxy, features);
|
||||
this.providers[handle] = provider;
|
||||
this.providerDisposables[handle] = this.scmService.registerSCMProvider(provider);
|
||||
$registerSourceControl(handle: number, id: string, label: string): void {
|
||||
const provider = new MainThreadSCMProvider(this._proxy, handle, id, label, this.scmService, this.commandService);
|
||||
this._sourceControls[handle] = provider;
|
||||
this._sourceControlDisposables[handle] = this.scmService.registerSCMProvider(provider);
|
||||
}
|
||||
|
||||
$unregister(handle: number): void {
|
||||
const provider = this.providers[handle];
|
||||
$updateSourceControl(handle: number, features: SCMProviderFeatures): void {
|
||||
const sourceControl = this._sourceControls[handle];
|
||||
|
||||
if (!sourceControl) {
|
||||
return;
|
||||
}
|
||||
|
||||
sourceControl.$updateSourceControl(features);
|
||||
}
|
||||
|
||||
$unregisterSourceControl(handle: number): void {
|
||||
const sourceControl = this._sourceControls[handle];
|
||||
|
||||
if (!sourceControl) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._sourceControlDisposables[handle].dispose();
|
||||
delete this._sourceControlDisposables[handle];
|
||||
|
||||
sourceControl.dispose();
|
||||
delete this._sourceControls[handle];
|
||||
}
|
||||
|
||||
$registerGroup(sourceControlHandle: number, groupHandle: number, id: string, label: string): void {
|
||||
const provider = this._sourceControls[sourceControlHandle];
|
||||
|
||||
if (!provider) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.providerDisposables[handle].dispose();
|
||||
delete this.providerDisposables[handle];
|
||||
|
||||
provider.dispose();
|
||||
delete this.providers[handle];
|
||||
provider.$registerGroup(groupHandle, id, label);
|
||||
}
|
||||
|
||||
$onChange(handle: number, rawResourceGroups: SCMRawResourceGroup[], count: number | undefined, state: string | undefined): void {
|
||||
const provider = this.providers[handle];
|
||||
$updateGroup(sourceControlHandle: number, groupHandle: number, features: SCMGroupFeatures): void {
|
||||
const provider = this._sourceControls[sourceControlHandle];
|
||||
|
||||
if (!provider) {
|
||||
return;
|
||||
}
|
||||
|
||||
provider.$onChange(rawResourceGroups, count, state);
|
||||
provider.$updateGroup(groupHandle, features);
|
||||
}
|
||||
|
||||
$updateGroupResourceStates(sourceControlHandle: number, groupHandle: number, resources: SCMRawResource[]): void {
|
||||
const provider = this._sourceControls[sourceControlHandle];
|
||||
|
||||
if (!provider) {
|
||||
return;
|
||||
}
|
||||
|
||||
provider.$updateGroupResourceStates(groupHandle, resources);
|
||||
}
|
||||
|
||||
$unregisterGroup(sourceControlHandle: number, handle: number): void {
|
||||
const provider = this._sourceControls[sourceControlHandle];
|
||||
|
||||
if (!provider) {
|
||||
return;
|
||||
}
|
||||
|
||||
provider.$unregisterGroup(handle);
|
||||
}
|
||||
|
||||
$setInputBoxValue(value: string): void {
|
||||
@@ -162,15 +231,15 @@ export class MainThreadSCM extends MainThreadSCMShape {
|
||||
}
|
||||
|
||||
private onDidChangeProvider(provider: ISCMProvider): void {
|
||||
const handle = Object.keys(this.providers).filter(handle => this.providers[handle] === provider)[0];
|
||||
this.proxy.$onActiveProviderChange(handle && parseInt(handle));
|
||||
const handle = Object.keys(this._sourceControls).filter(handle => this._sourceControls[handle] === provider)[0];
|
||||
this._proxy.$onActiveSourceControlChange(handle && parseInt(handle));
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
Object.keys(this.providers)
|
||||
.forEach(id => this.providers[id].dispose());
|
||||
Object.keys(this._sourceControls)
|
||||
.forEach(id => this._sourceControls[id].dispose());
|
||||
|
||||
this.providers = Object.create(null);
|
||||
this.disposables = dispose(this.disposables);
|
||||
this._sourceControls = Object.create(null);
|
||||
this._disposables = dispose(this._disposables);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user