mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 10:38:59 +01:00
MainThreadSCMProvider.$onChange
This commit is contained in:
@@ -232,12 +232,18 @@ export interface SCMProviderFeatures {
|
||||
commitCommand?: string;
|
||||
clickCommand?: string;
|
||||
dragCommand?: string;
|
||||
resourceGroups: vscode.SCMResourceGroup[];
|
||||
supportsOriginalResource: boolean;
|
||||
}
|
||||
|
||||
export interface SCMRawResource {
|
||||
uri: string;
|
||||
}
|
||||
|
||||
export abstract class MainThreadSCMShape {
|
||||
$register(id: string, features: SCMProviderFeatures): void { throw ni(); }
|
||||
$unregister(id: string): void { throw ni(); }
|
||||
$onChange(id: string, resources: SCMRawResource[][]): void { throw ni(); }
|
||||
}
|
||||
|
||||
// -- extension host
|
||||
|
||||
@@ -6,29 +6,30 @@
|
||||
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import Event, { Emitter, debounceEvent } from 'vs/base/common/event';
|
||||
import { index } from 'vs/base/common/arrays';
|
||||
import { asWinJsPromise } from 'vs/base/common/async';
|
||||
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
|
||||
import { SCMProvider } from 'vscode';
|
||||
import { Disposable } from 'vs/workbench/api/node/extHostTypes';
|
||||
import { MainContext, MainThreadSCMShape } from './extHost.protocol';
|
||||
import { MainContext, MainThreadSCMShape, SCMRawResource } from './extHost.protocol';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
export class ExtHostSCM {
|
||||
|
||||
private _proxy: MainThreadSCMShape;
|
||||
private _providers: { [id: string]: SCMProvider; } = Object.create(null);
|
||||
private _providers: { [id: string]: vscode.SCMProvider; } = Object.create(null);
|
||||
|
||||
private _onDidChangeActiveProvider = new Emitter<SCMProvider>();
|
||||
get onDidChangeActiveProvider(): Event<SCMProvider> { return this._onDidChangeActiveProvider.event; }
|
||||
private _onDidChangeActiveProvider = new Emitter<vscode.SCMProvider>();
|
||||
get onDidChangeActiveProvider(): Event<vscode.SCMProvider> { return this._onDidChangeActiveProvider.event; }
|
||||
|
||||
private _activeProvider: SCMProvider;
|
||||
get activeProvider(): SCMProvider | undefined { return this._activeProvider; }
|
||||
private _activeProvider: vscode.SCMProvider;
|
||||
get activeProvider(): vscode.SCMProvider | undefined { return this._activeProvider; }
|
||||
|
||||
constructor(threadService: IThreadService) {
|
||||
this._proxy = threadService.get(MainContext.MainThreadSCM);
|
||||
}
|
||||
|
||||
registerSCMProvider(id: string, provider: SCMProvider): Disposable {
|
||||
registerSCMProvider(id: string, provider: vscode.SCMProvider): Disposable {
|
||||
if (this._providers[id]) {
|
||||
throw new Error(`Provider ${id} already registered`);
|
||||
}
|
||||
@@ -36,14 +37,37 @@ export class ExtHostSCM {
|
||||
// TODO@joao: should pluck all the things out of the provider
|
||||
this._providers[id] = provider;
|
||||
|
||||
const resourceGroupsIds = provider.resourceGroups.map(g => g.id);
|
||||
|
||||
this._proxy.$register(id, {
|
||||
commitCommand: provider.commitCommand,
|
||||
clickCommand: provider.clickCommand,
|
||||
dragCommand: provider.dragCommand,
|
||||
resourceGroups: provider.resourceGroups,
|
||||
supportsOriginalResource: !!provider.getOriginalResource
|
||||
});
|
||||
|
||||
const onDidChange = debounceEvent<vscode.SCMResource[], vscode.SCMResource[]>(provider.onDidChange, (l, e) => e, 200);
|
||||
const onDidChangeListener = onDidChange(resources => {
|
||||
const resourceGroupsById = index(resourceGroupsIds, id => id, () => [] as SCMRawResource[]);
|
||||
|
||||
resources.forEach(resource => {
|
||||
const resourceGroup = resourceGroupsById[resource.resourceGroup];
|
||||
|
||||
if (!resourceGroup) {
|
||||
// TODO@Joao: ask Joh: should we warn? should we throw?
|
||||
return;
|
||||
}
|
||||
|
||||
resourceGroup.push({ uri: resource.uri.toString() });
|
||||
});
|
||||
|
||||
const result = resourceGroupsIds.map(id => resourceGroupsById[id]);
|
||||
this._proxy.$onChange(id, result);
|
||||
});
|
||||
|
||||
return new Disposable(() => {
|
||||
onDidChangeListener.dispose();
|
||||
delete this._providers[id];
|
||||
this._proxy.$unregister(id);
|
||||
});
|
||||
|
||||
@@ -6,32 +6,29 @@
|
||||
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { dispose } from 'vs/base/common/lifecycle';
|
||||
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
|
||||
import { ISCMService, ISCMProvider, ISCMResourceGroup, ISCMResource } from 'vs/workbench/services/scm/common/scm';
|
||||
import { ISCMService, ISCMProvider, ISCMResource } 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 } from './extHost.protocol';
|
||||
import { ExtHostContext, MainThreadSCMShape, ExtHostSCMShape, SCMProviderFeatures, SCMRawResource } from './extHost.protocol';
|
||||
import { SCMProvider } from 'vs/workbench/services/scm/common/scmProvider';
|
||||
|
||||
class MainThreadSCMProvider implements ISCMProvider {
|
||||
|
||||
get id(): string { return this._id; }
|
||||
|
||||
private _onChange = new Emitter<void>();
|
||||
get onChange(): Event<void> { return this._onChange.event; }
|
||||
|
||||
readonly resourceGroups: ISCMResourceGroup[] = [];
|
||||
private disposables: IDisposable[] = [];
|
||||
class MainThreadSCMProvider extends SCMProvider {
|
||||
|
||||
constructor(
|
||||
private _id: string,
|
||||
id: string,
|
||||
private proxy: ExtHostSCMShape,
|
||||
private features: SCMProviderFeatures,
|
||||
@ISCMService scmService: ISCMService,
|
||||
@ICommandService private commandService: ICommandService
|
||||
) {
|
||||
super(id, 'Ext Host SCM Provider');
|
||||
scmService.onDidChangeProvider(this.onDidChangeProvider, this, this.disposables);
|
||||
this.disposables.push(scmService.registerSCMProvider(this));
|
||||
|
||||
features.resourceGroups
|
||||
.forEach(resourceGroup => this.createResourceGroup(resourceGroup.id, resourceGroup.label));
|
||||
}
|
||||
|
||||
commit(message: string): TPromise<void> {
|
||||
@@ -72,6 +69,24 @@ class MainThreadSCMProvider implements ISCMProvider {
|
||||
return this.proxy.$getOriginalResource(this.id, uri);
|
||||
}
|
||||
|
||||
private onDidChangeProvider(provider: ISCMProvider): void {
|
||||
// if (provider === this) {
|
||||
// return
|
||||
// }
|
||||
}
|
||||
|
||||
$onChange(raw: SCMRawResource[][]): void {
|
||||
if (raw.length !== this.resourceGroups.length) {
|
||||
throw new Error('bad on change');
|
||||
}
|
||||
|
||||
raw.forEach((group, index) => {
|
||||
const resourceGroup = this.resourceGroups[index];
|
||||
const resources = group.map(raw => ({ uri: URI.parse(raw.uri) }));
|
||||
resourceGroup.set(...resources);
|
||||
});
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.disposables = dispose(this.disposables);
|
||||
}
|
||||
@@ -80,7 +95,7 @@ class MainThreadSCMProvider implements ISCMProvider {
|
||||
export class MainThreadSCM extends MainThreadSCMShape {
|
||||
|
||||
private proxy: ExtHostSCMShape;
|
||||
private providers: { [id: string]: IDisposable; } = Object.create(null);
|
||||
private providers: { [id: string]: MainThreadSCMProvider; } = Object.create(null);
|
||||
|
||||
constructor(
|
||||
@IThreadService threadService: IThreadService,
|
||||
@@ -105,6 +120,16 @@ export class MainThreadSCM extends MainThreadSCMShape {
|
||||
delete this.providers[id];
|
||||
}
|
||||
|
||||
$onChange(id: string, resources: SCMRawResource[][]): void {
|
||||
const provider = this.providers[id];
|
||||
|
||||
if (!provider) {
|
||||
return;
|
||||
}
|
||||
|
||||
provider.$onChange(resources);
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
Object.keys(this.providers)
|
||||
.forEach(id => this.providers[id].dispose());
|
||||
|
||||
Reference in New Issue
Block a user