debt - onDispose => onWillDispose

This commit is contained in:
Benjamin Pasero 2021-03-29 08:21:09 +02:00
parent c0fa3dfd3e
commit 5e3df4ce30
No known key found for this signature in database
GPG key ID: E6380CC4C8219E65
27 changed files with 61 additions and 90 deletions

View file

@ -51,15 +51,15 @@ import { ILogService } from 'vs/platform/log/common/log';
export class SimpleModel implements IResolvedTextEditorModel {
private readonly model: ITextModel;
private readonly _onDispose: Emitter<void>;
private readonly _onWillDispose: Emitter<void>;
constructor(model: ITextModel) {
this.model = model;
this._onDispose = new Emitter<void>();
this._onWillDispose = new Emitter<void>();
}
public get onDispose(): Event<void> {
return this._onDispose.event;
public get onWillDispose(): Event<void> {
return this._onWillDispose.event;
}
public load(): Promise<SimpleModel> {
@ -82,7 +82,7 @@ export class SimpleModel implements IResolvedTextEditorModel {
public dispose(): void {
this.disposed = true;
this._onDispose.fire();
this._onWillDispose.fire();
}
public isDisposed(): boolean {

View file

@ -9,9 +9,9 @@ import { Event } from 'vs/base/common/event';
export interface IEditorModel {
/**
* Emitted when the model is disposed.
* Emitted when the model is about to be disposed.
*/
readonly onDispose: Event<void>;
readonly onWillDispose: Event<void>;
/**
* Loads the model.

View file

@ -273,7 +273,7 @@ export class MainThreadWebviewPanels extends Disposable implements extHostProtoc
const disposables = new DisposableStore();
disposables.add(primary.webview.onDidFocus(() => this.updateWebviewViewStates(primary)));
disposables.add(secondary.webview.onDidFocus(() => this.updateWebviewViewStates(secondary)));
disposables.add(diffEditorInput.onDispose(() => {
disposables.add(diffEditorInput.onWillDispose(() => {
this._webviewFromDiffEditorHandles.delete(primary.id);
this._webviewFromDiffEditorHandles.delete(secondary.id);
dispose(disposables);

View file

@ -484,7 +484,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
this._register(this._group.onDidChangeEditorSticky(editor => this.onDidChangeEditorSticky(editor)));
this._register(this._group.onDidOpenEditor(editor => this.onDidOpenEditor(editor)));
this._register(this._group.onDidCloseEditor(editor => this.handleOnDidCloseEditor(editor)));
this._register(this._group.onDidDisposeEditor(editor => this.onDidDisposeEditor(editor)));
this._register(this._group.onWillDisposeEditor(editor => this.onWillDisposeEditor(editor)));
this._register(this._group.onDidChangeEditorDirty(editor => this.onDidChangeEditorDirty(editor)));
this._register(this._group.onDidEditorLabelChange(editor => this.onDidEditorLabelChange(editor)));
@ -584,7 +584,7 @@ export class EditorGroupView extends Themable implements IEditorGroupView {
return descriptor;
}
private onDidDisposeEditor(editor: EditorInput): void {
private onWillDisposeEditor(editor: EditorInput): void {
// To prevent race conditions, we handle disposed editors in our worker with a timeout
// because it can happen that an input is being disposed with the intent to replace

View file

@ -274,7 +274,7 @@ export class EditorMemento<T> implements IEditorMemento<T> {
}
if (!this.editorDisposables.has(editor)) {
this.editorDisposables.set(editor, Event.once(editor.onDispose)(() => {
this.editorDisposables.set(editor, Event.once(editor.onWillDispose)(() => {
this.clearEditorState(resource);
this.editorDisposables?.delete(editor);
}));

View file

@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IAction } from 'vs/base/common/actions';
import { Event } from 'vs/base/common/event';
export interface IComposite {
@ -33,21 +32,6 @@ export interface IComposite {
*/
getTitle(): string | undefined;
/**
* Returns the primary actions of the composite.
*/
getActions(): ReadonlyArray<IAction>;
/**
* Returns the secondary actions of the composite.
*/
getSecondaryActions(): ReadonlyArray<IAction>;
/**
* Returns an array of actions to show in the context menu of the composite
*/
getContextMenuActions(): ReadonlyArray<IAction>;
/**
* Returns the underlying control of this composite.
*/

View file

@ -373,9 +373,9 @@ export interface IMoveResult {
export interface IEditorInput extends IDisposable {
/**
* Triggered when this input is disposed.
* Triggered when this input is about to be disposed.
*/
readonly onDispose: Event<void>;
readonly onWillDispose: Event<void>;
/**
* Triggered when this input changes its dirty state.
@ -520,8 +520,8 @@ export abstract class EditorInput extends Disposable implements IEditorInput {
protected readonly _onDidChangeLabel = this._register(new Emitter<void>());
readonly onDidChangeLabel = this._onDidChangeLabel.event;
private readonly _onDispose = this._register(new Emitter<void>());
readonly onDispose = this._onDispose.event;
private readonly _onWillDispose = this._register(new Emitter<void>());
readonly onWillDispose = this._onWillDispose.event;
private disposed: boolean = false;
@ -616,7 +616,7 @@ export abstract class EditorInput extends Disposable implements IEditorInput {
dispose(): void {
if (!this.disposed) {
this.disposed = true;
this._onDispose.fire();
this._onWillDispose.fire();
}
super.dispose();
@ -764,14 +764,14 @@ export class SideBySideEditorInput extends EditorInput {
private registerListeners(): void {
// When the primary or secondary input gets disposed, dispose this diff editor input
const onceSecondaryDisposed = Event.once(this.secondary.onDispose);
const onceSecondaryDisposed = Event.once(this.secondary.onWillDispose);
this._register(onceSecondaryDisposed(() => {
if (!this.isDisposed()) {
this.dispose();
}
}));
const oncePrimaryDisposed = Event.once(this.primary.onDispose);
const oncePrimaryDisposed = Event.once(this.primary.onWillDispose);
this._register(oncePrimaryDisposed(() => {
if (!this.isDisposed()) {
this.dispose();
@ -873,8 +873,8 @@ export interface ITextEditorModel extends IEditorModel {
*/
export class EditorModel extends Disposable implements IEditorModel {
private readonly _onDispose = this._register(new Emitter<void>());
readonly onDispose = this._onDispose.event;
private readonly _onWillDispose = this._register(new Emitter<void>());
readonly onWillDispose = this._onWillDispose.event;
private disposed = false;
@ -904,7 +904,7 @@ export class EditorModel extends Disposable implements IEditorModel {
*/
dispose(): void {
this.disposed = true;
this._onDispose.fire();
this._onWillDispose.fire();
super.dispose();
}

View file

@ -73,8 +73,8 @@ export class EditorGroup extends Disposable {
private readonly _onDidCloseEditor = this._register(new Emitter<EditorCloseEvent>());
readonly onDidCloseEditor = this._onDidCloseEditor.event;
private readonly _onDidDisposeEditor = this._register(new Emitter<EditorInput>());
readonly onDidDisposeEditor = this._onDidDisposeEditor.event;
private readonly _onWillDisposeEditor = this._register(new Emitter<EditorInput>());
readonly onWillDisposeEditor = this._onWillDisposeEditor.event;
private readonly _onDidChangeEditorDirty = this._register(new Emitter<EditorInput>());
readonly onDidChangeEditorDirty = this._onDidChangeEditorDirty.event;
@ -315,9 +315,9 @@ export class EditorGroup extends Disposable {
const listeners = new DisposableStore();
// Re-emit disposal of editor input as our own event
listeners.add(Event.once(editor.onDispose)(() => {
listeners.add(Event.once(editor.onWillDispose)(() => {
if (this.indexOf(editor) >= 0) {
this._onDidDisposeEditor.fire(editor);
this._onWillDisposeEditor.fire(editor);
}
}));

View file

@ -121,7 +121,7 @@ export class FileEditorInput extends AbstractTextResourceEditorInput implements
this.modelListeners.add(model.onDidSaveError(() => this._onDidChangeDirty.fire()));
// remove model association once it gets disposed
this.modelListeners.add(Event.once(model.onDispose)(() => {
this.modelListeners.add(Event.once(model.onWillDispose)(() => {
this.modelListeners.clear();
this.model = undefined;
}));

View file

@ -264,7 +264,7 @@ export class SettingsEditor2 extends EditorPane {
this._setOptions(options);
this._register(input.onDispose(() => {
this._register(input.onWillDispose(() => {
this.searchWidget.setValue('');
}));

View file

@ -220,7 +220,7 @@ export class SearchView extends ViewPane {
this.viewletState = this.memento.getMemento(StorageScope.WORKSPACE, StorageTarget.USER);
this._register(this.fileService.onDidFilesChange(e => this.onFilesChanged(e)));
this._register(this.textFileService.untitled.onDidDispose(model => this.onUntitledDidDispose(model.resource)));
this._register(this.textFileService.untitled.onWillDispose(model => this.onUntitledDidDispose(model.resource)));
this._register(this.contextService.onDidChangeWorkbenchState(() => this.onDidChangeWorkbenchState()));
this._register(this.searchHistoryService.onDidClearHistory(() => this.clearHistory()));

View file

@ -311,7 +311,7 @@ export const getOrMakeSearchEditorInput = (
const input = instantiationService.createInstance(SearchEditorInput, modelUri, existingData.backingUri, model);
inputs.set(cacheKey, input);
input.onDispose(() => inputs.delete(cacheKey));
input.onWillDispose(() => inputs.delete(cacheKey));
return input;
};

View file

@ -91,7 +91,7 @@ export class ReleaseNotesManager {
undefined);
this._currentReleaseNotes.webview.onDidClickLink(uri => this.onDidClickLink(URI.parse(uri)));
this._currentReleaseNotes.onDispose(() => { this._currentReleaseNotes = undefined; });
this._currentReleaseNotes.onWillDispose(() => { this._currentReleaseNotes = undefined; });
this._currentReleaseNotes.webview.html = html;
}

View file

@ -1080,7 +1080,7 @@ export class EditorService extends Disposable implements EditorServiceImpl {
// created the model initially, the lifecycle for
// untitled is tightly coupled with the editor
// lifecycle for now.
Event.once(input.onDispose)(() => untitledModel.dispose());
Event.once(input.onWillDispose)(() => untitledModel.dispose());
return input;
}) as EditorInput;
@ -1196,7 +1196,7 @@ export class EditorService extends Disposable implements EditorServiceImpl {
// Otherwise create and add to cache
input = factoryFn();
this.editorInputCache.set(resource, input);
Event.once(input.onDispose)(() => this.editorInputCache.delete(resource));
Event.once(input.onWillDispose)(() => this.editorInputCache.delete(resource));
return input;
}

View file

@ -262,7 +262,7 @@ export class HistoryService extends Disposable implements IHistoryService {
}
private onEditorDispose(editor: EditorInput, listener: Function, mapEditorToDispose: Map<EditorInput, DisposableStore>): void {
const toDispose = Event.once(editor.onDispose)(() => listener());
const toDispose = Event.once(editor.onWillDispose)(() => listener());
let disposables = mapEditorToDispose.get(editor);
if (!disposables) {

View file

@ -130,7 +130,7 @@ export class SettingsEditorModel extends AbstractSettingsModel implements ISetti
constructor(reference: IReference<ITextEditorModel>, private _configurationTarget: ConfigurationTarget) {
super();
this.settingsModel = reference.object.textEditorModel!;
this._register(this.onDispose(() => reference.dispose()));
this._register(this.onWillDispose(() => reference.dispose()));
this._register(this.settingsModel.onDidChangeContent(() => {
this._settingsGroups = undefined;
this._onDidChangeGroups.fire();
@ -725,7 +725,7 @@ export class DefaultSettingsEditorModel extends AbstractSettingsModel implements
this._register(defaultSettings.onDidChange(() => this._onDidChangeGroups.fire()));
this._model = reference.object.textEditorModel!;
this._register(this.onDispose(() => reference.dispose()));
this._register(this.onWillDispose(() => reference.dispose()));
}
get uri(): URI {

View file

@ -180,8 +180,8 @@ export class ProgressService extends Disposable implements IProgressService {
private readonly _onDidReport = this._register(new Emitter<IProgressStep>());
readonly onDidReport = this._onDidReport.event;
private readonly _onDispose = this._register(new Emitter<void>());
readonly onDispose = this._onDispose.event;
private readonly _onWillDispose = this._register(new Emitter<void>());
readonly onWillDispose = this._onWillDispose.event;
private _step: IProgressStep | undefined = undefined;
get step() { return this._step; }
@ -215,7 +215,7 @@ export class ProgressService extends Disposable implements IProgressService {
dispose(): void {
this._done = true;
this._onDispose.fire();
this._onWillDispose.fire();
super.dispose();
}
@ -252,7 +252,7 @@ export class ProgressService extends Disposable implements IProgressService {
promise.finally(() => onDidReportListener.dispose());
// When the progress model gets disposed, we are done as well
Event.once(progressStateModel.onDispose)(() => promiseResolve());
Event.once(progressStateModel.onWillDispose)(() => promiseResolve());
return promise;
});
@ -381,7 +381,7 @@ export class ProgressService extends Disposable implements IProgressService {
// Show initially
updateNotification(progressStateModel.step);
const listener = progressStateModel.onDidReport(step => updateNotification(step));
Event.once(progressStateModel.onDispose)(() => listener.dispose());
Event.once(progressStateModel.onWillDispose)(() => listener.dispose());
// Clean up eventually
(async () => {

View file

@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { IAction } from 'vs/base/common/actions';
import { IEditorControl } from 'vs/workbench/common/editor';
import { CompositeScope, CompositeProgressIndicator } from 'vs/workbench/services/progress/browser/progressIndicator';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
@ -24,9 +23,6 @@ class TestViewlet implements IViewlet {
hasFocus() { return false; }
getId(): string { return this.id; }
getTitle(): string { return this.id; }
getActions(): IAction[] { return []; }
getSecondaryActions(): IAction[] { return []; }
getContextMenuActions(): IAction[] { return []; }
getControl(): IEditorControl { return null!; }
focus(): void { }
getOptimalWidth(): number { return 10; }

View file

@ -395,7 +395,7 @@ export class TextFileEditorModelManager extends Disposable implements ITextFileE
// store in cache but remove when model gets disposed
this.mapResourceToModel.set(resource, model);
this.mapResourceToDisposeListener.set(resource, model.onDispose(() => this.remove(resource)));
this.mapResourceToDisposeListener.set(resource, model.onWillDispose(() => this.remove(resource)));
}
protected remove(resource: URI): void {

View file

@ -57,7 +57,7 @@ suite('Workbench - TextModelResolverService', () => {
assert.strictEqual(snapshotToString(((model as ResourceEditorModel).createSnapshot()!)), 'Hello Test');
let disposed = false;
let disposedPromise = new Promise<void>(resolve => {
Event.once(model.onDispose)(() => {
Event.once(model.onWillDispose)(() => {
disposed = true;
resolve();
});
@ -84,7 +84,7 @@ suite('Workbench - TextModelResolverService', () => {
assert.strictEqual(editorModel.getValue(), 'Hello Html');
let disposed = false;
Event.once(model.onDispose)(() => {
Event.once(model.onWillDispose)(() => {
disposed = true;
});
@ -104,7 +104,7 @@ suite('Workbench - TextModelResolverService', () => {
const ref = await accessor.textModelResolverService.createModelReference(textModel.resource);
let disposed = false;
Event.once(loadedModel.onDispose)(() => {
Event.once(loadedModel.onWillDispose)(() => {
disposed = true;
});
@ -129,7 +129,7 @@ suite('Workbench - TextModelResolverService', () => {
const ref1 = await accessor.textModelResolverService.createModelReference(textModel.resource);
let disposed = false;
Event.once(loadedModel.onDispose)(() => {
Event.once(loadedModel.onWillDispose)(() => {
disposed = true;
});

View file

@ -80,9 +80,9 @@ export interface IUntitledTextEditorModelManager {
readonly onDidChangeLabel: Event<IUntitledTextEditorModel>;
/**
* Events for when untitled text editors are disposed.
* Events for when untitled text editors are about to be disposed.
*/
readonly onDidDispose: Event<IUntitledTextEditorModel>;
readonly onWillDispose: Event<IUntitledTextEditorModel>;
/**
* Creates a new untitled editor model with the provided options. If the `untitledResource`
@ -130,8 +130,8 @@ export class UntitledTextEditorService extends Disposable implements IUntitledTe
private readonly _onDidChangeEncoding = this._register(new Emitter<IUntitledTextEditorModel>());
readonly onDidChangeEncoding = this._onDidChangeEncoding.event;
private readonly _onDidDispose = this._register(new Emitter<IUntitledTextEditorModel>());
readonly onDidDispose = this._onDidDispose.event;
private readonly _onWillDispose = this._register(new Emitter<IUntitledTextEditorModel>());
readonly onWillDispose = this._onWillDispose.event;
private readonly _onDidChangeLabel = this._register(new Emitter<IUntitledTextEditorModel>());
readonly onDidChangeLabel = this._onDidChangeLabel.event;
@ -236,10 +236,10 @@ export class UntitledTextEditorService extends Disposable implements IUntitledTe
modelListeners.add(model.onDidChangeDirty(() => this._onDidChangeDirty.fire(model)));
modelListeners.add(model.onDidChangeName(() => this._onDidChangeLabel.fire(model)));
modelListeners.add(model.onDidChangeEncoding(() => this._onDidChangeEncoding.fire(model)));
modelListeners.add(model.onDispose(() => this._onDidDispose.fire(model)));
modelListeners.add(model.onWillDispose(() => this._onWillDispose.fire(model)));
// Remove from cache on dispose
Event.once(model.onDispose)(() => {
Event.once(model.onWillDispose)(() => {
// Registry
this.mapResourceToModel.delete(model.resource);

View file

@ -351,13 +351,13 @@ suite('Untitled text editors', () => {
model.dispose();
});
test('service#onDidDisposeModel', async () => {
test('service#onWillDispose', async () => {
const service = accessor.untitledTextEditorService;
const input = instantiationService.createInstance(UntitledTextEditorInput, service.create());
let counter = 0;
service.onDidDispose(model => {
service.onWillDispose(model => {
counter++;
assert.strictEqual(model.resource.toString(), input.resource.toString());
});

View file

@ -106,7 +106,7 @@ suite('Workbench editor groups', () => {
group.onDidChangeEditorPinned(e => group.isPinned(e) ? groupEvents.pinned.push(e) : groupEvents.unpinned.push(e));
group.onDidChangeEditorSticky(e => group.isSticky(e) ? groupEvents.sticky.push(e) : groupEvents.unsticky.push(e));
group.onDidMoveEditor(e => groupEvents.moved.push(e));
group.onDidDisposeEditor(e => groupEvents.disposed.push(e));
group.onWillDisposeEditor(e => groupEvents.disposed.push(e));
return groupEvents;
}

View file

@ -27,7 +27,7 @@ suite('Workbench editor input', () => {
assert(!input.matches(null));
assert(input.getName());
input.onDispose(() => {
input.onWillDispose(() => {
assert(true);
counter++;
});
@ -41,13 +41,13 @@ suite('Workbench editor input', () => {
let counter = 0;
let input = new MyEditorInput();
input.onDispose(() => {
input.onWillDispose(() => {
assert(true);
counter++;
});
let otherInput = new MyEditorInput();
otherInput.onDispose(() => {
otherInput.onWillDispose(() => {
assert(true);
counter++;
});
@ -72,7 +72,7 @@ suite('Workbench editor input', () => {
let otherInput = new MyEditorInput();
let diffInput = instantiationService.createInstance(DiffEditorInput, 'name', 'description', input, otherInput, undefined);
diffInput.onDispose(() => {
diffInput.onWillDispose(() => {
counter++;
assert(true);
});
@ -83,7 +83,7 @@ suite('Workbench editor input', () => {
otherInput = new MyEditorInput();
let diffInput2 = instantiationService.createInstance(DiffEditorInput, 'name', 'description', input, otherInput, undefined);
diffInput2.onDispose(() => {
diffInput2.onWillDispose(() => {
counter++;
assert(true);
});

View file

@ -67,7 +67,7 @@ suite('Workbench editor model', () => {
const model = new MyEditorModel();
model.onDispose(() => {
model.onWillDispose(() => {
assert(true);
counter++;
});

View file

@ -112,7 +112,7 @@ suite('Workbench EditorPane', () => {
e.setVisible(true, group);
assert(e.isVisible());
assert.strictEqual(e.group, group);
input.onDispose(() => {
input.onWillDispose(() => {
assert(false);
});
e.dispose();

View file

@ -136,9 +136,6 @@ export class TestWorkingCopy extends Disposable implements IWorkingCopy {
private readonly _onDidChangeContent = this._register(new Emitter<void>());
readonly onDidChangeContent = this._onDidChangeContent.event;
private readonly _onDispose = this._register(new Emitter<void>());
readonly onDispose = this._onDispose.event;
readonly capabilities = WorkingCopyCapabilities.None;
readonly name = basename(this.resource);
@ -177,12 +174,6 @@ export class TestWorkingCopy extends Disposable implements IWorkingCopy {
async backup(token: CancellationToken): Promise<IWorkingCopyBackup> {
return {};
}
dispose(): void {
this._onDispose.fire();
super.dispose();
}
}
export class TestWorkingCopyFileService implements IWorkingCopyFileService {