Skip to content

Commit

Permalink
Replace TPromise in settings #53526
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Nov 7, 2018
1 parent ca6e101 commit 83660da
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 179 deletions.
23 changes: 11 additions & 12 deletions src/vs/workbench/parts/preferences/browser/preferencesActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import { Action } from 'vs/base/common/actions';
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { IModelService } from 'vs/editor/common/services/modelService';
import { IModeService } from 'vs/editor/common/services/modeService';
import * as nls from 'vs/nls';
Expand All @@ -30,7 +29,7 @@ export class OpenRawDefaultSettingsAction extends Action {
super(id, label);
}

public run(event?: any): TPromise<any> {
public run(event?: any): Thenable<any> {
return this.preferencesService.openRawDefaultSettings();
}
}
Expand All @@ -48,7 +47,7 @@ export class OpenSettings2Action extends Action {
super(id, label);
}

public run(event?: any): TPromise<any> {
public run(event?: any): Thenable<any> {
return this.preferencesService.openSettings(false);
}
}
Expand All @@ -66,7 +65,7 @@ export class OpenSettingsAction extends Action {
super(id, label);
}

public run(event?: any): TPromise<any> {
public run(event?: any): Thenable<any> {
return this.preferencesService.openSettings();
}
}
Expand All @@ -84,7 +83,7 @@ export class OpenSettingsJsonAction extends Action {
super(id, label);
}

public run(event?: any): TPromise<any> {
public run(event?: any): Thenable<any> {
return this.preferencesService.openSettings(true);
}
}
Expand All @@ -102,7 +101,7 @@ export class OpenGlobalSettingsAction extends Action {
super(id, label);
}

public run(event?: any): TPromise<any> {
public run(event?: any): Thenable<any> {
return this.preferencesService.openGlobalSettings();
}
}
Expand All @@ -120,7 +119,7 @@ export class OpenGlobalKeybindingsAction extends Action {
super(id, label);
}

public run(event?: any): TPromise<any> {
public run(event?: any): Thenable<any> {
return this.preferencesService.openGlobalKeybindingSettings(false);
}
}
Expand All @@ -138,7 +137,7 @@ export class OpenGlobalKeybindingsFileAction extends Action {
super(id, label);
}

public run(event?: any): TPromise<any> {
public run(event?: any): Thenable<any> {
return this.preferencesService.openGlobalKeybindingSettings(true);
}
}
Expand All @@ -156,7 +155,7 @@ export class OpenDefaultKeybindingsFileAction extends Action {
super(id, label);
}

public run(event?: any): TPromise<any> {
public run(event?: any): Thenable<any> {
return this.preferencesService.openDefaultKeybindingsFile();
}
}
Expand All @@ -183,7 +182,7 @@ export class OpenWorkspaceSettingsAction extends Action {
this.enabled = this.workspaceContextService.getWorkbenchState() !== WorkbenchState.EMPTY;
}

public run(event?: any): TPromise<any> {
public run(event?: any): Thenable<any> {
return this.preferencesService.openWorkspaceSettings();
}

Expand Down Expand Up @@ -220,7 +219,7 @@ export class OpenFolderSettingsAction extends Action {
this.enabled = this.workspaceContextService.getWorkbenchState() === WorkbenchState.WORKSPACE && this.workspaceContextService.getWorkspace().folders.length > 0;
}

public run(): TPromise<any> {
public run(): Thenable<any> {
return this.commandService.executeCommand<IWorkspaceFolder>(PICK_WORKSPACE_FOLDER_COMMAND_ID)
.then(workspaceFolder => {
if (workspaceFolder) {
Expand Down Expand Up @@ -253,7 +252,7 @@ export class ConfigureLanguageBasedSettingsAction extends Action {
super(id, label);
}

public run(): TPromise<any> {
public run(): Thenable<any> {
const languages = this.modeService.getRegisteredLanguageNames();
const picks: IQuickPickItem[] = languages.sort().map((lang, index) => {
let description: string = nls.localize('languageDescriptionConfigured', "({0})", this.modeService.getModeIdForLanguageName(lang.toLowerCase()));
Expand Down
65 changes: 32 additions & 33 deletions src/vs/workbench/parts/preferences/browser/preferencesEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { ArrayNavigator } from 'vs/base/common/iterator';
import { Disposable, dispose, IDisposable } from 'vs/base/common/lifecycle';
import * as strings from 'vs/base/common/strings';
import { URI } from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { EditorExtensionsRegistry, IEditorContributionCtor, registerEditorContribution } from 'vs/editor/browser/editorExtensions';
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
Expand Down Expand Up @@ -204,7 +203,7 @@ export class PreferencesEditor extends BaseEditor {
super.setEditorVisible(visible, group);
}

private updateInput(newInput: PreferencesEditorInput, options: EditorOptions, token: CancellationToken): TPromise<void> {
private updateInput(newInput: PreferencesEditorInput, options: EditorOptions, token: CancellationToken): Promise<void> {
return this.sideBySidePreferencesWidget.setInput(<DefaultPreferencesEditorInput>newInput.details, <EditorInput>newInput.master, options, token).then(({ defaultPreferencesRenderer, editablePreferencesRenderer }) => {
if (token.isCancellationRequested) {
return void 0;
Expand All @@ -230,12 +229,12 @@ export class PreferencesEditor extends BaseEditor {
});
}

private triggerSearch(query: string): TPromise<void> {
private triggerSearch(query: string): Promise<void> {
if (query) {
return TPromise.join([
return Promise.all([
this.localSearchDelayer.trigger(() => this.preferencesRenderers.localFilterPreferences(query).then(() => { })),
this.remoteSearchThrottle.trigger(() => TPromise.wrap(this.progressService.showWhile(this.preferencesRenderers.remoteSearchPreferences(query), 500)))
]) as TPromise;
this.remoteSearchThrottle.trigger(() => Promise.resolve(this.progressService.showWhile(this.preferencesRenderers.remoteSearchPreferences(query), 500)))
]).then(() => { });
} else {
// When clearing the input, update immediately to clear it
this.localSearchDelayer.cancel();
Expand All @@ -251,8 +250,8 @@ export class PreferencesEditor extends BaseEditor {
if (this.editorService.activeControl !== this) {
this.focus();
}
const promise = this.input && this.input.isDirty() ? this.input.save() : TPromise.as(true);
promise.then(value => {
const promise: Thenable<boolean> = this.input && this.input.isDirty() ? this.input.save() : Promise.resolve(true);
promise.then(() => {
if (target === ConfigurationTarget.USER) {
this.preferencesService.switchSettings(ConfigurationTarget.USER, this.preferencesService.userSettingsResource, true);
} else if (target === ConfigurationTarget.WORKSPACE) {
Expand Down Expand Up @@ -438,7 +437,7 @@ class PreferencesRenderersController extends Disposable {
this._prefsModelsForSearch = new Map<string, ISettingsEditorModel>();
}

remoteSearchPreferences(query: string, updateCurrentResults?: boolean): TPromise<void> {
remoteSearchPreferences(query: string, updateCurrentResults?: boolean): Promise<void> {
if (this.lastFilterResult && this.lastFilterResult.exactMatch) {
// Skip and clear remote search
query = '';
Expand Down Expand Up @@ -467,7 +466,7 @@ class PreferencesRenderersController extends Disposable {
});
}

localFilterPreferences(query: string, updateCurrentResults?: boolean): TPromise<boolean> {
localFilterPreferences(query: string, updateCurrentResults?: boolean): Promise<boolean> {
if (this._settingsNavigator) {
this._settingsNavigator.reset();
}
Expand All @@ -476,18 +475,18 @@ class PreferencesRenderersController extends Disposable {
return this.filterOrSearchPreferences(query, this._currentLocalSearchProvider, 'filterResult', nls.localize('filterResult', "Filtered Results"), 0, undefined, updateCurrentResults);
}

private filterOrSearchPreferences(query: string, searchProvider: ISearchProvider, groupId: string, groupLabel: string, groupOrder: number, token?: CancellationToken, editableContentOnly?: boolean): TPromise<boolean> {
private filterOrSearchPreferences(query: string, searchProvider: ISearchProvider, groupId: string, groupLabel: string, groupOrder: number, token?: CancellationToken, editableContentOnly?: boolean): Promise<boolean> {
this._lastQuery = query;

const filterPs: TPromise<IFilterResult>[] = [this._filterOrSearchPreferences(query, this.editablePreferencesRenderer, searchProvider, groupId, groupLabel, groupOrder, token)];
const filterPs: Promise<IFilterResult>[] = [this._filterOrSearchPreferences(query, this.editablePreferencesRenderer, searchProvider, groupId, groupLabel, groupOrder, token)];
if (!editableContentOnly) {
filterPs.push(
this._filterOrSearchPreferences(query, this.defaultPreferencesRenderer, searchProvider, groupId, groupLabel, groupOrder, token));
filterPs.push(
this.searchAllSettingsTargets(query, searchProvider, groupId, groupLabel, groupOrder, token).then(() => null));
}

return TPromise.join(filterPs).then(results => {
return Promise.all(filterPs).then(results => {
let [editableFilterResult, defaultFilterResult] = results;

if (!defaultFilterResult && editableContentOnly) {
Expand All @@ -501,7 +500,7 @@ class PreferencesRenderersController extends Disposable {
});
}

private searchAllSettingsTargets(query: string, searchProvider: ISearchProvider, groupId: string, groupLabel: string, groupOrder: number, token?: CancellationToken): TPromise<void> {
private searchAllSettingsTargets(query: string, searchProvider: ISearchProvider, groupId: string, groupLabel: string, groupOrder: number, token?: CancellationToken): Promise<void> {
const searchPs = [
this.searchSettingsTarget(query, searchProvider, ConfigurationTarget.WORKSPACE, groupId, groupLabel, groupOrder, token),
this.searchSettingsTarget(query, searchProvider, ConfigurationTarget.USER, groupId, groupLabel, groupOrder, token)
Expand All @@ -513,7 +512,7 @@ class PreferencesRenderersController extends Disposable {
}


return TPromise.join(searchPs).then(() => { });
return Promise.all(searchPs).then(() => { });
}

private searchSettingsTarget(query: string, provider: ISearchProvider, target: SettingsTarget, groupId: string, groupLabel: string, groupOrder: number, token?: CancellationToken): Promise<void> {
Expand All @@ -530,7 +529,7 @@ class PreferencesRenderersController extends Disposable {
this._onDidFilterResultsCountChange.fire({ target, count });
}, err => {
if (!isPromiseCanceledError(err)) {
return TPromise.wrapError(err);
return Promise.reject(err);
}

return null;
Expand Down Expand Up @@ -582,9 +581,9 @@ class PreferencesRenderersController extends Disposable {
}
}

private _filterOrSearchPreferences(filter: string, preferencesRenderer: IPreferencesRenderer<ISetting>, provider: ISearchProvider, groupId: string, groupLabel: string, groupOrder: number, token?: CancellationToken): TPromise<IFilterResult> {
private _filterOrSearchPreferences(filter: string, preferencesRenderer: IPreferencesRenderer<ISetting>, provider: ISearchProvider, groupId: string, groupLabel: string, groupOrder: number, token?: CancellationToken): Promise<IFilterResult> {
if (!preferencesRenderer) {
return TPromise.wrap(null);
return Promise.resolve(null);
}

const model = <ISettingsEditorModel>preferencesRenderer.preferencesModel;
Expand All @@ -594,12 +593,12 @@ class PreferencesRenderersController extends Disposable {
});
}

private _filterOrSearchPreferencesModel(filter: string, model: ISettingsEditorModel, provider: ISearchProvider, groupId: string, groupLabel: string, groupOrder: number, token?: CancellationToken): TPromise<IFilterResult> {
const searchP = provider ? provider.searchModel(model, token) : TPromise.wrap(null);
private _filterOrSearchPreferencesModel(filter: string, model: ISettingsEditorModel, provider: ISearchProvider, groupId: string, groupLabel: string, groupOrder: number, token?: CancellationToken): Promise<IFilterResult> {
const searchP = provider ? provider.searchModel(model, token) : Promise.resolve(null);
return searchP
.then<ISearchResult>(null, err => {
if (isPromiseCanceledError(err)) {
return TPromise.wrapError(err);
return Promise.reject(err);
} else {
/* __GDPR__
"defaultSettings.searchError" : {
Expand Down Expand Up @@ -845,10 +844,10 @@ class SideBySidePreferencesWidget extends Widget {
this._register(focusTracker.onDidFocus(() => this._onFocus.fire()));
}

public setInput(defaultPreferencesEditorInput: DefaultPreferencesEditorInput, editablePreferencesEditorInput: EditorInput, options: EditorOptions, token: CancellationToken): TPromise<{ defaultPreferencesRenderer?: IPreferencesRenderer<ISetting>, editablePreferencesRenderer?: IPreferencesRenderer<ISetting> }> {
public setInput(defaultPreferencesEditorInput: DefaultPreferencesEditorInput, editablePreferencesEditorInput: EditorInput, options: EditorOptions, token: CancellationToken): Promise<{ defaultPreferencesRenderer?: IPreferencesRenderer<ISetting>, editablePreferencesRenderer?: IPreferencesRenderer<ISetting> }> {
this.getOrCreateEditablePreferencesEditor(editablePreferencesEditorInput);
this.settingsTargetsWidget.settingsTarget = this.getSettingsTarget(editablePreferencesEditorInput.getResource());
return TPromise.join([
return Promise.all([
this.updateInput(this.defaultPreferencesEditor, defaultPreferencesEditorInput, DefaultSettingsEditorContribution.ID, editablePreferencesEditorInput.getResource(), options, token),
this.updateInput(this.editablePreferencesEditor, editablePreferencesEditorInput, SettingsEditorContribution.ID, defaultPreferencesEditorInput.getResource(), options, token)
])
Expand Down Expand Up @@ -1076,13 +1075,13 @@ export class DefaultPreferencesEditor extends BaseTextEditor {

interface ISettingsEditorContribution extends editorCommon.IEditorContribution {

updatePreferencesRenderer(associatedPreferencesModelUri: URI): TPromise<IPreferencesRenderer<ISetting>>;
updatePreferencesRenderer(associatedPreferencesModelUri: URI): Thenable<IPreferencesRenderer<ISetting>>;

}

abstract class AbstractSettingsEditorContribution extends Disposable implements ISettingsEditorContribution {

private preferencesRendererCreationPromise: TPromise<IPreferencesRenderer<ISetting>>;
private preferencesRendererCreationPromise: Thenable<IPreferencesRenderer<ISetting>>;

constructor(protected editor: ICodeEditor,
@IInstantiationService protected instantiationService: IInstantiationService,
Expand All @@ -1093,7 +1092,7 @@ abstract class AbstractSettingsEditorContribution extends Disposable implements
this._register(this.editor.onDidChangeModel(() => this._onModelChanged()));
}

updatePreferencesRenderer(associatedPreferencesModelUri: URI): TPromise<IPreferencesRenderer<ISetting>> {
updatePreferencesRenderer(associatedPreferencesModelUri: URI): Thenable<IPreferencesRenderer<ISetting>> {
if (!this.preferencesRendererCreationPromise) {
this.preferencesRendererCreationPromise = this._createPreferencesRenderer();
}
Expand All @@ -1103,7 +1102,7 @@ abstract class AbstractSettingsEditorContribution extends Disposable implements
.then(changed => changed ? this._updatePreferencesRenderer(associatedPreferencesModelUri) : this.preferencesRendererCreationPromise);
}

return TPromise.as(null);
return Promise.resolve(null);
}

protected _onModelChanged(): void {
Expand All @@ -1114,13 +1113,13 @@ abstract class AbstractSettingsEditorContribution extends Disposable implements
}
}

private _hasAssociatedPreferencesModelChanged(associatedPreferencesModelUri: URI): TPromise<boolean> {
private _hasAssociatedPreferencesModelChanged(associatedPreferencesModelUri: URI): Thenable<boolean> {
return this.preferencesRendererCreationPromise.then(preferencesRenderer => {
return !(preferencesRenderer && preferencesRenderer.getAssociatedPreferencesModel() && preferencesRenderer.getAssociatedPreferencesModel().uri.toString() === associatedPreferencesModelUri.toString());
});
}

private _updatePreferencesRenderer(associatedPreferencesModelUri: URI): TPromise<IPreferencesRenderer<ISetting>> {
private _updatePreferencesRenderer(associatedPreferencesModelUri: URI): Thenable<IPreferencesRenderer<ISetting>> {
return this.preferencesService.createPreferencesEditorModel<ISetting>(associatedPreferencesModelUri)
.then(associatedPreferencesEditorModel => {
return this.preferencesRendererCreationPromise.then(preferencesRenderer => {
Expand Down Expand Up @@ -1148,7 +1147,7 @@ abstract class AbstractSettingsEditorContribution extends Disposable implements
preferencesRenderer.dispose();
}
});
this.preferencesRendererCreationPromise = TPromise.as(null);
this.preferencesRendererCreationPromise = Promise.resolve(null);
}
}

Expand All @@ -1157,7 +1156,7 @@ abstract class AbstractSettingsEditorContribution extends Disposable implements
super.dispose();
}

protected abstract _createPreferencesRenderer(): TPromise<IPreferencesRenderer<ISetting>>;
protected abstract _createPreferencesRenderer(): Thenable<IPreferencesRenderer<ISetting>>;
abstract getId(): string;
}

Expand All @@ -1169,7 +1168,7 @@ class DefaultSettingsEditorContribution extends AbstractSettingsEditorContributi
return DefaultSettingsEditorContribution.ID;
}

protected _createPreferencesRenderer(): TPromise<IPreferencesRenderer<ISetting>> {
protected _createPreferencesRenderer(): Thenable<IPreferencesRenderer<ISetting>> {
return this.preferencesService.createPreferencesEditorModel(this.editor.getModel().uri)
.then(editorModel => {
if (editorModel instanceof DefaultSettingsEditorModel && this.editor.getModel()) {
Expand Down Expand Up @@ -1199,7 +1198,7 @@ class SettingsEditorContribution extends AbstractSettingsEditorContribution impl
return SettingsEditorContribution.ID;
}

protected _createPreferencesRenderer(): TPromise<IPreferencesRenderer<ISetting>> {
protected _createPreferencesRenderer(): Thenable<IPreferencesRenderer<ISetting>> {
if (this.isSettingsModel()) {
return this.preferencesService.createPreferencesEditorModel(this.editor.getModel().uri)
.then(settingsModel => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { MarkdownString } from 'vs/base/common/htmlContent';
import { KeyCode } from 'vs/base/common/keyCodes';
import { Disposable, dispose, IDisposable } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import { IMarginData } from 'vs/editor/browser/controller/mouseTarget';
import { ICodeEditor, IEditorMouseEvent, IViewZone, MouseTargetType } from 'vs/editor/browser/editorBrowser';
import { ICursorPositionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
Expand Down Expand Up @@ -549,13 +548,13 @@ export class SettingsTargetsWidget extends Widget {
}
}

public updateTarget(settingsTarget: SettingsTarget): TPromise<void> {
public updateTarget(settingsTarget: SettingsTarget): Promise<void> {
const isSameTarget = this.settingsTarget === settingsTarget || settingsTarget instanceof URI && this.settingsTarget instanceof URI && this.settingsTarget.toString() === settingsTarget.toString();
if (!isSameTarget) {
this.settingsTarget = settingsTarget;
this._onDidTargetChange.fire(this.settingsTarget);
}
return TPromise.as(null);
return Promise.resolve(null);
}

private update(): void {
Expand Down
Loading

0 comments on commit 83660da

Please sign in to comment.