diff --git a/src/vs/workbench/api/browser/mainThreadDocuments.ts b/src/vs/workbench/api/browser/mainThreadDocuments.ts index 26f70ce9e9b..cd22db56f9d 100644 --- a/src/vs/workbench/api/browser/mainThreadDocuments.ts +++ b/src/vs/workbench/api/browser/mainThreadDocuments.ts @@ -216,7 +216,7 @@ export class MainThreadDocuments implements MainThreadDocumentsShape { } private _doCreateUntitled(resource?: URI, mode?: string, initialValue?: string): Promise { - return this._textFileService.untitled.loadOrCreate({ + return this._textFileService.untitled.resolve({ resource, mode, initialValue, diff --git a/src/vs/workbench/api/browser/mainThreadWebview.ts b/src/vs/workbench/api/browser/mainThreadWebview.ts index bac1b9b6ba2..96a9f791863 100644 --- a/src/vs/workbench/api/browser/mainThreadWebview.ts +++ b/src/vs/workbench/api/browser/mainThreadWebview.ts @@ -309,7 +309,7 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma } private async retainCustomEditorModel(webviewInput: WebviewInput, resource: URI, viewType: string, capabilities: readonly extHostProtocol.WebviewEditorCapabilities[]) { - const model = await this._customEditorService.models.loadOrCreate(webviewInput.getResource(), webviewInput.viewType); + const model = await this._customEditorService.models.resolve(webviewInput.getResource(), webviewInput.viewType); const existingEntry = this._customEditorModels.get(model); if (existingEntry) { diff --git a/src/vs/workbench/contrib/backup/test/electron-browser/backupRestorer.test.ts b/src/vs/workbench/contrib/backup/test/electron-browser/backupRestorer.test.ts index 0d6726b0314..5092ec55d40 100644 --- a/src/vs/workbench/contrib/backup/test/electron-browser/backupRestorer.test.ts +++ b/src/vs/workbench/contrib/backup/test/electron-browser/backupRestorer.test.ts @@ -127,12 +127,12 @@ suite('BackupRestorer', () => { for (const editor of editorService.editors) { const resource = editor.getResource(); if (isEqual(resource, untitledFile1)) { - const model = await accessor.textFileService.untitled.loadOrCreate({ resource }); + const model = await accessor.textFileService.untitled.resolve({ resource }); assert.equal(model.textEditorModel.getValue(), 'untitled-1'); model.dispose(); counter++; } else if (isEqual(resource, untitledFile2)) { - const model = await accessor.textFileService.untitled.loadOrCreate({ resource }); + const model = await accessor.textFileService.untitled.resolve({ resource }); assert.equal(model.textEditorModel.getValue(), 'untitled-2'); model.dispose(); counter++; diff --git a/src/vs/workbench/contrib/customEditor/browser/customEditorInput.ts b/src/vs/workbench/contrib/customEditor/browser/customEditorInput.ts index 1ff775a4dc3..cc3b9df79af 100644 --- a/src/vs/workbench/contrib/customEditor/browser/customEditorInput.ts +++ b/src/vs/workbench/contrib/customEditor/browser/customEditorInput.ts @@ -155,7 +155,7 @@ export class CustomFileEditorInput extends LazilyResolvedWebviewEditorInput { } public async resolve(): Promise { - this._model = await this.customEditorService.models.loadOrCreate(this.getResource(), this.viewType); + this._model = await this.customEditorService.models.resolve(this.getResource(), this.viewType); this._register(this._model.onDidChangeDirty(() => this._onDidChangeDirty.fire())); if (this.isDirty()) { this._onDidChangeDirty.fire(); diff --git a/src/vs/workbench/contrib/customEditor/common/customEditor.ts b/src/vs/workbench/contrib/customEditor/common/customEditor.ts index 79fa6b1874d..8ed8a3ffd6d 100644 --- a/src/vs/workbench/contrib/customEditor/common/customEditor.ts +++ b/src/vs/workbench/contrib/customEditor/common/customEditor.ts @@ -47,7 +47,7 @@ export type CustomEditorEdit = { source?: any, data: any }; export interface ICustomEditorModelManager { get(resource: URI, viewType: string): ICustomEditorModel | undefined; - loadOrCreate(resource: URI, viewType: string): Promise; + resolve(resource: URI, viewType: string): Promise; disposeModel(model: ICustomEditorModel): void; } diff --git a/src/vs/workbench/contrib/customEditor/common/customEditorModelManager.ts b/src/vs/workbench/contrib/customEditor/common/customEditorModelManager.ts index 62271532b12..15719e65079 100644 --- a/src/vs/workbench/contrib/customEditor/common/customEditorModelManager.ts +++ b/src/vs/workbench/contrib/customEditor/common/customEditorModelManager.ts @@ -21,7 +21,7 @@ export class CustomEditorModelManager implements ICustomEditorModelManager { return this._models.get(this.key(resource, viewType))?.model; } - public async loadOrCreate(resource: URI, viewType: string): Promise { + public async resolve(resource: URI, viewType: string): Promise { const existing = this.get(resource, viewType); if (existing) { return existing; diff --git a/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts b/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts index 7855e0f4382..e4656bacabc 100644 --- a/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts +++ b/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts @@ -285,7 +285,7 @@ export class FileEditorInput extends TextEditorInput implements IFileEditorInput // Resolve as text try { - await this.textFileService.files.loadOrCreate(this.resource, { + await this.textFileService.files.resolve(this.resource, { mode: this.preferredMode, encoding: this.preferredEncoding, reload: { async: true }, // trigger a reload of the model if it exists already but do not wait to show the model @@ -295,7 +295,7 @@ export class FileEditorInput extends TextEditorInput implements IFileEditorInput // This is a bit ugly, because we first resolve the model and then resolve a model reference. the reason being that binary // or very large files do not resolve to a text file model but should be opened as binary files without text. First calling into - // loadOrCreate ensures we are not creating model references for these kind of resources. + // resolve() ensures we are not creating model references for these kind of resources. // In addition we have a bit of payload to take into account (encoding, reload) that the text resolver does not handle yet. if (!this.textModelReference) { this.textModelReference = this.textModelResolverService.createModelReference(this.resource); diff --git a/src/vs/workbench/contrib/files/test/browser/editorAutoSave.test.ts b/src/vs/workbench/contrib/files/test/browser/editorAutoSave.test.ts index 63057f06a59..7f8f47c2b25 100644 --- a/src/vs/workbench/contrib/files/test/browser/editorAutoSave.test.ts +++ b/src/vs/workbench/contrib/files/test/browser/editorAutoSave.test.ts @@ -87,7 +87,7 @@ suite('EditorAutoSave', () => { const resource = toResource.call(this, '/path/index.txt'); - const model = await accessor.textFileService.files.loadOrCreate(resource) as IResolvedTextFileEditorModel; + const model = await accessor.textFileService.files.resolve(resource) as IResolvedTextFileEditorModel; model.textEditorModel.setValue('Super Good'); diff --git a/src/vs/workbench/contrib/files/test/browser/fileEditorTracker.test.ts b/src/vs/workbench/contrib/files/test/browser/fileEditorTracker.test.ts index 9c8046394a0..05025f0d1a8 100644 --- a/src/vs/workbench/contrib/files/test/browser/fileEditorTracker.test.ts +++ b/src/vs/workbench/contrib/files/test/browser/fileEditorTracker.test.ts @@ -62,7 +62,7 @@ suite('Files - FileEditorTracker', () => { const resource = toResource.call(this, '/path/index.txt'); - const model = await accessor.textFileService.files.loadOrCreate(resource) as IResolvedTextFileEditorModel; + const model = await accessor.textFileService.files.resolve(resource) as IResolvedTextFileEditorModel; model.textEditorModel.setValue('Super Good'); assert.equal(snapshotToString(model.createSnapshot()!), 'Super Good'); @@ -108,7 +108,7 @@ suite('Files - FileEditorTracker', () => { assert.ok(!accessor.editorService.isOpen({ resource })); - const model = await accessor.textFileService.files.loadOrCreate(resource) as IResolvedTextFileEditorModel; + const model = await accessor.textFileService.files.resolve(resource) as IResolvedTextFileEditorModel; model.textEditorModel.setValue('Super Good'); diff --git a/src/vs/workbench/services/textfile/browser/textFileService.ts b/src/vs/workbench/services/textfile/browser/textFileService.ts index 3102d410f66..9e2c92dde45 100644 --- a/src/vs/workbench/services/textfile/browser/textFileService.ts +++ b/src/vs/workbench/services/textfile/browser/textFileService.ts @@ -275,7 +275,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex // we know the file has changed on disk after the move and the // model might have still existed with the previous state. this // ensures we are not tracking a stale state. - const restoredModel = await this.files.loadOrCreate(modelToRestore.resource, { reload: { async: false }, encoding: modelToRestore.encoding, mode: modelToRestore.mode }); + const restoredModel = await this.files.resolve(modelToRestore.resource, { reload: { async: false }, encoding: modelToRestore.encoding, mode: modelToRestore.mode }); // restore previous dirty content if any and ensure to mark // the model as dirty @@ -522,7 +522,7 @@ export abstract class AbstractTextFileService extends Disposable implements ITex } try { - targetModel = await this.files.loadOrCreate(target, { encoding: sourceModelEncoding, mode }); + targetModel = await this.files.resolve(target, { encoding: sourceModelEncoding, mode }); } catch (error) { // if the target already exists and was not created by us, it is possible // that we cannot load the target as text model if it is binary or too diff --git a/src/vs/workbench/services/textfile/common/textFileEditorModelManager.ts b/src/vs/workbench/services/textfile/common/textFileEditorModelManager.ts index 4fbc86a0d1f..91f374863a0 100644 --- a/src/vs/workbench/services/textfile/common/textFileEditorModelManager.ts +++ b/src/vs/workbench/services/textfile/common/textFileEditorModelManager.ts @@ -92,7 +92,7 @@ export class TextFileEditorModelManager extends Disposable implements ITextFileE return this.mapResourceToModel.get(resource); } - async loadOrCreate(resource: URI, options?: IModelLoadOrCreateOptions): Promise { + async resolve(resource: URI, options?: IModelLoadOrCreateOptions): Promise { // Return early if model is currently being loaded const pendingLoad = this.mapResourceToPendingModelLoaders.get(resource); diff --git a/src/vs/workbench/services/textfile/common/textfiles.ts b/src/vs/workbench/services/textfile/common/textfiles.ts index f2be03d36c4..8d298a49f68 100644 --- a/src/vs/workbench/services/textfile/common/textfiles.ts +++ b/src/vs/workbench/services/textfile/common/textfiles.ts @@ -320,9 +320,9 @@ export interface IModelLoadOrCreateOptions { /** * If the model was already loaded before, allows to trigger * a reload of it to fetch the latest contents: - * - async: loadOrCreate() will return immediately and trigger + * - async: resolve() will return immediately and trigger * a reload that will run in the background. - * - sync: loadOrCreate() will only return resolved when the + * - sync: resolve() will only return resolved when the * model has finished reloading. */ reload?: { @@ -357,7 +357,7 @@ export interface ITextFileEditorModelManager { get(resource: URI): ITextFileEditorModel | undefined; - loadOrCreate(resource: URI, options?: IModelLoadOrCreateOptions): Promise; + resolve(resource: URI, options?: IModelLoadOrCreateOptions): Promise; disposeModel(model: ITextFileEditorModel): void; } diff --git a/src/vs/workbench/services/textfile/test/textFileEditorModelManager.test.ts b/src/vs/workbench/services/textfile/test/textFileEditorModelManager.test.ts index c43162b1712..6a089108b14 100644 --- a/src/vs/workbench/services/textfile/test/textFileEditorModelManager.test.ts +++ b/src/vs/workbench/services/textfile/test/textFileEditorModelManager.test.ts @@ -87,21 +87,21 @@ suite('Files - TextFileEditorModelManager', () => { model3.dispose(); }); - test('loadOrCreate', async () => { + test('resolve', async () => { const manager: TextFileEditorModelManager = instantiationService.createInstance(TextFileEditorModelManager); const resource = URI.file('/test.html'); const encoding = 'utf8'; - const model = await manager.loadOrCreate(resource, { encoding }); + const model = await manager.resolve(resource, { encoding }); assert.ok(model); assert.equal(model.getEncoding(), encoding); assert.equal(manager.get(resource), model); - const model2 = await manager.loadOrCreate(resource, { encoding }); + const model2 = await manager.resolve(resource, { encoding }); assert.equal(model2, model); model.dispose(); - const model3 = await manager.loadOrCreate(resource, { encoding }); + const model3 = await manager.resolve(resource, { encoding }); assert.notEqual(model3, model2); assert.equal(manager.get(resource), model3); model3.dispose(); @@ -174,13 +174,13 @@ suite('Files - TextFileEditorModelManager', () => { } }); - const model1 = await manager.loadOrCreate(resource1, { encoding: 'utf8' }); + const model1 = await manager.resolve(resource1, { encoding: 'utf8' }); assert.equal(loadedCounter, 1); accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource: resource1, type: FileChangeType.DELETED }])); accessor.fileService.fireFileChanges(new FileChangesEvent([{ resource: resource1, type: FileChangeType.ADDED }])); - const model2 = await manager.loadOrCreate(resource2, { encoding: 'utf8' }); + const model2 = await manager.resolve(resource2, { encoding: 'utf8' }); assert.equal(loadedCounter, 2); model1.textEditorModel!.setValue('changed'); @@ -211,7 +211,7 @@ suite('Files - TextFileEditorModelManager', () => { const resource = toResource.call(this, '/path/index_something.txt'); - const model = await manager.loadOrCreate(resource, { encoding: 'utf8' }); + const model = await manager.resolve(resource, { encoding: 'utf8' }); model.dispose(); assert.ok(!manager.get(resource)); assert.ok(!accessor.modelService.getModel(model.resource)); @@ -223,7 +223,7 @@ suite('Files - TextFileEditorModelManager', () => { const resource = toResource.call(this, '/path/index_something.txt'); - const model = await manager.loadOrCreate(resource, { encoding: 'utf8' }); + const model = await manager.resolve(resource, { encoding: 'utf8' }); model.textEditorModel!.setValue('make dirty'); manager.disposeModel((model as TextFileEditorModel)); assert.ok(!model.isDisposed()); @@ -243,10 +243,10 @@ suite('Files - TextFileEditorModelManager', () => { const resource = toResource.call(this, '/path/index_something.txt'); - let model = await manager.loadOrCreate(resource, { mode }); + let model = await manager.resolve(resource, { mode }); assert.equal(model.textEditorModel!.getModeId(), mode); - model = await manager.loadOrCreate(resource, { mode: 'text' }); + model = await manager.resolve(resource, { mode: 'text' }); assert.equal(model.textEditorModel!.getModeId(), PLAINTEXT_MODE_ID); manager.disposeModel((model as TextFileEditorModel)); diff --git a/src/vs/workbench/services/textfile/test/textFileService.test.ts b/src/vs/workbench/services/textfile/test/textFileService.test.ts index 07ca1554156..a96a70a1bce 100644 --- a/src/vs/workbench/services/textfile/test/textFileService.test.ts +++ b/src/vs/workbench/services/textfile/test/textFileService.test.ts @@ -64,7 +64,7 @@ suite('Files - TextFileService', () => { assert.ok(accessor.textFileService.isDirty(model.resource)); - const untitled = await accessor.textFileService.untitled.loadOrCreate(); + const untitled = await accessor.textFileService.untitled.resolve(); assert.ok(!accessor.textFileService.isDirty(untitled.resource)); untitled.textEditorModel.setValue('changed'); @@ -94,7 +94,7 @@ suite('Files - TextFileService', () => { const mockedFileUri = untitledUncUri.with({ scheme: Schemas.file }); const mockedEditorInput = instantiationService.createInstance(TextFileEditorModel, mockedFileUri, 'utf8', undefined); - const loadOrCreateStub = sinon.stub(accessor.textFileService.files, 'loadOrCreate', () => Promise.resolve(mockedEditorInput)); + const loadOrCreateStub = sinon.stub(accessor.textFileService.files, 'resolve', () => Promise.resolve(mockedEditorInput)); sinon.stub(accessor.textFileService.untitled, 'exists', () => true); sinon.stub(accessor.textFileService.untitled, 'hasAssociatedFilePath', () => true); diff --git a/src/vs/workbench/services/textmodelResolver/common/textModelResolverService.ts b/src/vs/workbench/services/textmodelResolver/common/textModelResolverService.ts index 147bbd7e861..5e2952dc265 100644 --- a/src/vs/workbench/services/textmodelResolver/common/textModelResolverService.ts +++ b/src/vs/workbench/services/textmodelResolver/common/textModelResolverService.ts @@ -38,7 +38,7 @@ class ResourceModelCollection extends ReferenceCollection; + resolve(options?: IUntitledCreationOptions): Promise; /** * A check to find out if a untitled resource has a file path associated or not. @@ -193,7 +193,7 @@ export class UntitledTextEditorService extends Disposable implements IUntitledTe return input; } - loadOrCreate(options?: IUntitledCreationOptions): Promise { + resolve(options?: IUntitledCreationOptions): Promise { return this.createOrGet(options).resolve(); } diff --git a/src/vs/workbench/test/common/editor/untitledTextEditor.test.ts b/src/vs/workbench/test/common/editor/untitledTextEditor.test.ts index 71ceb0c788c..4593daa0c94 100644 --- a/src/vs/workbench/test/common/editor/untitledTextEditor.test.ts +++ b/src/vs/workbench/test/common/editor/untitledTextEditor.test.ts @@ -73,7 +73,7 @@ suite('Workbench untitled text editors', () => { // dirty const model = await input2.resolve(); - assert.equal(await service.loadOrCreate({ resource: input2.getResource() }), model); + assert.equal(await service.resolve({ resource: input2.getResource() }), model); assert.ok(!input2.isDirty());