🎨 fix scm api based on @jrieken's recommendations

This commit is contained in:
Joao Moreno
2017-03-27 15:35:30 +02:00
parent b055708234
commit e06a838265
7 changed files with 49 additions and 42 deletions

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import { Emitter } from 'vs/base/common/event';
import { Emitter, mapEvent } from 'vs/base/common/event';
import { TrieMap } from 'vs/base/common/map';
import { score } from 'vs/editor/common/modes/languageSelector';
import * as Platform from 'vs/base/common/platform';
@@ -451,6 +451,11 @@ export function createApiFactory(initData: IInitData, threadService: IThreadServ
return extHostSCM.onDidChangeActiveProvider;
}
@proposed(extension)
get onDidAcceptInputValue() {
return mapEvent(extHostSCM.inputBox.onDidAccept, () => extHostSCM.inputBox);
}
@proposed(extension)
get inputBox() {
return extHostSCM.inputBox;

View File

@@ -24,7 +24,7 @@ function getIconPath(decorations: vscode.SCMResourceThemableDecorations) {
return undefined;
}
class ExtHostSCMInputBox {
export class ExtHostSCMInputBox {
private _value: string = '';
@@ -84,7 +84,7 @@ export class ExtHostSCM {
get activeProvider(): vscode.SCMProvider | undefined { return this._activeProvider; }
private _inputBox: ExtHostSCMInputBox;
get inputBox(): vscode.SCMInputBox { return this._inputBox; }
get inputBox(): ExtHostSCMInputBox { return this._inputBox; }
constructor(threadService: IThreadService) {
this._proxy = threadService.get(MainContext.MainThreadSCM);
@@ -100,15 +100,15 @@ export class ExtHostSCM {
label: provider.label,
contextKey: provider.contextKey,
supportsOpen: !!provider.open,
supportsOriginalResource: !!provider.getOriginalResource
supportsOriginalResource: !!provider.provideOriginalResource
});
const onDidChange = debounceEvent(provider.onDidChange || createEmptyEvent(), (l, e) => e, 100);
const onDidChangeListener = onDidChange(resourceGroups => {
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 = resourceGroups.map(g => {
const rawResourceGroups = scmProvider.resources.map(g => {
const rawResources = g.resources.map(r => {
const uri = r.uri.toString();
cache.set(uri, r);
@@ -164,7 +164,8 @@ export class ExtHostSCM {
return TPromise.as(null);
}
return asWinJsPromise(token => provider.open(resource, token));
provider.open(resource);
return TPromise.as(null);
}
$getOriginalResource(handle: number, uri: URI): TPromise<URI> {
@@ -174,7 +175,7 @@ export class ExtHostSCM {
return TPromise.as(null);
}
return asWinJsPromise(token => provider.getOriginalResource(uri, token));
return asWinJsPromise(token => provider.provideOriginalResource(uri, token));
}
$onInputBoxValueChange(value: string): TPromise<void> {

View File

@@ -7,6 +7,7 @@
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 { 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';
@@ -45,12 +46,13 @@ class MainThreadSCMProvider implements ISCMProvider {
this.disposables.push(scmService.registerSCMProvider(this));
}
open(resource: ISCMResource): TPromise<void> {
open(resource: ISCMResource): void {
if (!this.features.supportsOpen) {
return TPromise.as(null);
return;
}
return this.proxy.$open(this.handle, resource.uri.toString());
this.proxy.$open(this.handle, resource.uri.toString())
.done(null, onUnexpectedError);
}
getOriginalResource(uri: URI): TPromise<URI> {