Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/common/editor/editorModel.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Emitter } from '../../../base/common/event.js';
7
import { Disposable } from '../../../base/common/lifecycle.js';
8
9
/**
10
* The editor model is the heavyweight counterpart of editor input. Depending on the editor input, it
11
* resolves from a file system retrieve content and may allow for saving it back or reverting it.
12
* Editor models are typically cached for some while because they are expensive to construct.
13
*/
14
export class EditorModel extends Disposable {
15
16
private readonly _onWillDispose = this._register(new Emitter<void>());
17
readonly onWillDispose = this._onWillDispose.event;
18
19
private resolved = false;
20
21
/**
22
* Causes this model to resolve returning a promise when loading is completed.
23
*/
24
async resolve(): Promise<void> {
25
this.resolved = true;
26
}
27
28
/**
29
* Returns whether this model was loaded or not.
30
*/
31
isResolved(): boolean {
32
return this.resolved;
33
}
34
35
/**
36
* Find out if this model has been disposed.
37
*/
38
isDisposed(): boolean {
39
return this._store.isDisposed;
40
}
41
42
/**
43
* Subclasses should implement to free resources that have been claimed through loading.
44
*/
45
override dispose(): void {
46
this._onWillDispose.fire();
47
48
super.dispose();
49
}
50
}
51
52