git status through extension!

This commit is contained in:
Joao Moreno
2016-12-01 10:29:12 +01:00
parent 27793c49e8
commit e0e2be3384
10 changed files with 88 additions and 254 deletions

View File

@@ -229,21 +229,20 @@ export abstract class MainProcessExtensionServiceShape {
}
export interface SCMProviderFeatures {
label: string;
commitCommand?: string;
clickCommand?: string;
dragCommand?: string;
resourceGroups: vscode.SCMResourceGroup[];
supportsOriginalResource: boolean;
}
export interface SCMRawResource {
uri: string;
}
export type SCMRawResource = [string /*uri*/];
export type SCMRawResourceGroup = [string /*id*/, string /*label*/, SCMRawResource[]];
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(); }
$onChange(id: string, resources: SCMRawResourceGroup[]): void { throw ni(); }
}
// -- extension host

View File

@@ -6,12 +6,11 @@
import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import Event, { Emitter/*, debounceEvent*/ } from 'vs/base/common/event';
// import { index } from 'vs/base/common/arrays';
import Event, { Emitter, debounceEvent } 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*/ } from './extHost.protocol';
import { MainContext, MainThreadSCMShape, SCMRawResource, SCMRawResourceGroup } from './extHost.protocol';
import * as vscode from 'vscode';
export class ExtHostSCM {
@@ -37,37 +36,26 @@ 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, {
label: provider.label,
commitCommand: provider.commitCommand,
clickCommand: provider.clickCommand,
dragCommand: provider.dragCommand,
supportsOriginalResource: !!provider.getOriginalResource
});
// this._proxy.$register(id, {
// commitCommand: provider.commitCommand,
// clickCommand: provider.clickCommand,
// dragCommand: provider.dragCommand,
// resourceGroups: provider.resourceGroups,
// supportsOriginalResource: !!provider.getOriginalResource
// });
const onDidChange = debounceEvent(provider.onDidChange, (l, e) => e, 200);
const onDidChangeListener = onDidChange(resourceGroups => {
const rawResourceGroups = resourceGroups.map(g => {
const rawResources = g.resources.map(r => [r.uri.toString()] as SCMRawResource);
return [g.id, g.label, rawResources] as SCMRawResourceGroup;
});
// 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);
// });
this._proxy.$onChange(id, rawResourceGroups);
});
return new Disposable(() => {
// onDidChangeListener.dispose();
onDidChangeListener.dispose();
delete this._providers[id];
this._proxy.$unregister(id);
});

View File

@@ -6,29 +6,36 @@
import { TPromise } from 'vs/base/common/winjs.base';
import URI from 'vs/base/common/uri';
import { dispose } from 'vs/base/common/lifecycle';
import Event, { Emitter } from 'vs/base/common/event';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
import { ISCMService, ISCMProvider, ISCMResource } from 'vs/workbench/services/scm/common/scm';
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, SCMRawResource } from './extHost.protocol';
import { SCMProvider } from 'vs/workbench/services/scm/common/scmProvider';
import { ExtHostContext, MainThreadSCMShape, ExtHostSCMShape, SCMProviderFeatures, SCMRawResourceGroup } from './extHost.protocol';
class MainThreadSCMProvider extends SCMProvider {
class MainThreadSCMProvider implements ISCMProvider {
private _resources: ISCMResourceGroup[] = [];
get resources(): ISCMResourceGroup[] { return this._resources; }
private _onDidChange = new Emitter<ISCMResourceGroup[]>();
get onDidChange(): Event<ISCMResourceGroup[]> { return this._onDidChange.event; }
private disposables: IDisposable[] = [];
get id(): string { return this._id; }
get label(): string { return this.features.label; }
constructor(
id: string,
private _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> {
@@ -75,16 +82,20 @@ class MainThreadSCMProvider extends SCMProvider {
// }
}
$onChange(raw: SCMRawResource[][]): void {
if (raw.length !== this.resourceGroups.length) {
throw new Error('bad on change');
}
$onChange(rawResourceGroups: SCMRawResourceGroup[]): void {
this._resources = rawResourceGroups.map(rawGroup => {
const [id, label, rawResources] = rawGroup;
raw.forEach((group, index) => {
const resourceGroup = this.resourceGroups[index];
const resources = group.map(raw => ({ uri: URI.parse(raw.uri) }));
resourceGroup.set(...resources);
const resources = rawResources.map(rawResource => {
const [uri] = rawResource;
return { uri: URI.parse(uri) };
});
return { id, label, resources };
});
this._onDidChange.fire(this.resources);
}
dispose(): void {
@@ -120,14 +131,14 @@ export class MainThreadSCM extends MainThreadSCMShape {
delete this.providers[id];
}
$onChange(id: string, resources: SCMRawResource[][]): void {
$onChange(id: string, rawResourceGroups: SCMRawResourceGroup[]): void {
const provider = this.providers[id];
if (!provider) {
return;
}
provider.$onChange(resources);
provider.$onChange(rawResourceGroups);
}
dispose(): void {