Skip to content

Commit 17c1929

Browse files
author
Benjamin Pasero
committed
model - add a isDisposed method to generic editor models
1 parent b9ff832 commit 17c1929

5 files changed

Lines changed: 22 additions & 10 deletions

File tree

src/vs/editor/standalone/browser/simpleServices.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,17 @@ export class SimpleModel implements IResolvedTextEditorModel {
7878
return false;
7979
}
8080

81+
private disposed = false;
8182
public dispose(): void {
83+
this.disposed = true;
84+
8285
this._onDispose.fire();
8386
}
8487

88+
public isDisposed(): boolean {
89+
return this.disposed;
90+
}
91+
8592
public isResolved(): boolean {
8693
return true;
8794
}

src/vs/platform/editor/common/editor.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ export interface IEditorModel {
1818
*/
1919
load(): Promise<IEditorModel>;
2020

21+
/**
22+
* Find out if this model has been disposed.
23+
*/
24+
isDisposed(): boolean;
25+
2126
/**
2227
* Dispose associated resources
2328
*/

src/vs/workbench/common/editor.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,8 @@ export class EditorModel extends Disposable implements IEditorModel {
819819
private readonly _onDispose = this._register(new Emitter<void>());
820820
readonly onDispose = this._onDispose.event;
821821

822+
private disposed = false;
823+
822824
/**
823825
* Causes this model to load returning a promise when loading is completed.
824826
*/
@@ -833,10 +835,15 @@ export class EditorModel extends Disposable implements IEditorModel {
833835
return true;
834836
}
835837

838+
isDisposed(): boolean {
839+
return this.disposed;
840+
}
841+
836842
/**
837843
* Subclasses should implement to free resources that have been claimed through loading.
838844
*/
839845
dispose(): void {
846+
this.disposed = true;
840847
this._onDispose.fire();
841848

842849
super.dispose();

src/vs/workbench/services/textfile/common/textFileEditorModel.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
8686
private inConflictMode = false;
8787
private inOrphanMode = false;
8888
private inErrorMode = false;
89-
private disposed = false;
9089

9190
constructor(
9291
public readonly resource: URI,
@@ -147,15 +146,15 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
147146
// file is really gone and not just a faulty file event.
148147
await timeout(100);
149148

150-
if (this.disposed) {
149+
if (this.isDisposed()) {
151150
newInOrphanModeValidated = true;
152151
} else {
153152
const exists = await this.fileService.exists(this.resource);
154153
newInOrphanModeValidated = !exists;
155154
}
156155
}
157156

158-
if (this.inOrphanMode !== newInOrphanModeValidated && !this.disposed) {
157+
if (this.inOrphanMode !== newInOrphanModeValidated && !this.isDisposed()) {
159158
this.setOrphaned(newInOrphanModeValidated);
160159
}
161160
}
@@ -697,7 +696,7 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
697696
// one after the other without waiting for the save() to complete. If we are disposed(), we risk
698697
// saving contents to disk that are stale (see https://github.com/Microsoft/vscode/issues/50942).
699698
// To fix this issue, we will not store the contents to disk when we got disposed.
700-
if (this.disposed) {
699+
if (this.isDisposed()) {
701700
return;
702701
}
703702

@@ -955,18 +954,13 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
955954
return this.fileService.hasCapability(this.resource, FileSystemProviderCapabilities.Readonly);
956955
}
957956

958-
isDisposed(): boolean {
959-
return this.disposed;
960-
}
961-
962957
getStat(): IFileStatWithMetadata | undefined {
963958
return this.lastResolvedFileStat;
964959
}
965960

966961
dispose(): void {
967962
this.logService.trace('[text file model] dispose()', this.resource.toString(true));
968963

969-
this.disposed = true;
970964
this.inConflictMode = false;
971965
this.inOrphanMode = false;
972966
this.inErrorMode = false;

src/vs/workbench/services/textfile/common/textfiles.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ export interface ITextFileEditorModel extends ITextEditorModel, IEncodingSupport
425425
getMode(): string | undefined;
426426

427427
isResolved(): this is IResolvedTextFileEditorModel;
428-
isDisposed(): boolean;
429428
}
430429

431430
export function isTextFileEditorModel(model: ITextEditorModel): model is ITextFileEditorModel {

0 commit comments

Comments
 (0)