use object hierarchy in API

This commit is contained in:
Joao Moreno
2016-11-30 15:56:29 +01:00
parent 06b160e34e
commit 27793c49e8
4 changed files with 92 additions and 70 deletions

View File

@@ -6,12 +6,12 @@
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 { index } from 'vs/base/common/arrays';
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*/ } from './extHost.protocol';
import * as vscode from 'vscode';
export class ExtHostSCM {
@@ -37,37 +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);
// 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
});
// 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[]);
// 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];
// resources.forEach(resource => {
// const resourceGroup = resourceGroupsById[resource.resourceGroup];
if (!resourceGroup) {
// TODO@Joao: ask Joh: should we warn? should we throw?
return;
}
// if (!resourceGroup) {
// // TODO@Joao: ask Joh: should we warn? should we throw?
// return;
// }
resourceGroup.push({ uri: resource.uri.toString() });
});
// resourceGroup.push({ uri: resource.uri.toString() });
// });
const result = resourceGroupsIds.map(id => resourceGroupsById[id]);
this._proxy.$onChange(id, result);
});
// const result = resourceGroupsIds.map(id => resourceGroupsById[id]);
// this._proxy.$onChange(id, result);
// });
return new Disposable(() => {
onDidChangeListener.dispose();
// onDidChangeListener.dispose();
delete this._providers[id];
this._proxy.$unregister(id);
});