diff --git a/src/sql/workbench/browser/modelComponents/editor.component.ts b/src/sql/workbench/browser/modelComponents/editor.component.ts index 1ee86e02b4..ec54db459e 100644 --- a/src/sql/workbench/browser/modelComponents/editor.component.ts +++ b/src/sql/workbench/browser/modelComponents/editor.component.ts @@ -71,7 +71,7 @@ export default class EditorComponent extends ComponentBase { - const fileInput = this._editorService.createEditorInput(editorInput) as FileEditorInput; + async (editorInput, group) => { + const fileInput = await this._editorService.createEditorInput(editorInput) as FileEditorInput; // Try to convert the input, falling back to just a plain file input if we're unable to const newInput = this.convertInput(fileInput); return { editor: newInput, options: editorInput.options, group: group }; }, undefined, - (diffEditorInput, group) => { - const diffEditorInputImpl = this._editorService.createEditorInput(diffEditorInput) as DiffEditorInput; + async (diffEditorInput, group) => { + const diffEditorInputImpl = await this._editorService.createEditorInput(diffEditorInput) as DiffEditorInput; // Try to convert the input, falling back to the original input if we're unable to const newInput = this.convertInput(diffEditorInputImpl); return { editor: newInput, options: diffEditorInput.options, group: group }; diff --git a/src/sql/workbench/contrib/query/browser/query.contribution.ts b/src/sql/workbench/contrib/query/browser/query.contribution.ts index 560b17a88b..f2ffaa388e 100644 --- a/src/sql/workbench/contrib/query/browser/query.contribution.ts +++ b/src/sql/workbench/contrib/query/browser/query.contribution.ts @@ -546,8 +546,8 @@ export class QueryEditorOverrideContribution extends Disposable implements IWork // Fall back to using the normal text based diff editor - we don't want the query bar and related items showing up in the diff editor canHandleDiff: () => false }, - (editorInput, group) => { - const fileInput = this._editorService.createEditorInput(editorInput) as FileEditorInput; + async (editorInput, group) => { + const fileInput = await this._editorService.createEditorInput(editorInput) as FileEditorInput; const langAssociation = languageAssociationRegistry.getAssociationForLanguage(lang); const queryEditorInput = langAssociation?.syncConvertInput?.(fileInput); if (!queryEditorInput) { diff --git a/src/sql/workbench/services/notebook/browser/notebookServiceImpl.ts b/src/sql/workbench/services/notebook/browser/notebookServiceImpl.ts index 756c509126..2cf8544b02 100644 --- a/src/sql/workbench/services/notebook/browser/notebookServiceImpl.ts +++ b/src/sql/workbench/services/notebook/browser/notebookServiceImpl.ts @@ -309,7 +309,7 @@ export class NotebookService extends Disposable implements INotebookService { fileInput = this._instantiationService.createInstance(UntitledTextEditorInput, model); } else { let input: any = { forceFile: true, resource: uri, mode: languageMode }; - fileInput = this._editorService.createEditorInput(input); + fileInput = await this._editorService.createEditorInput(input); } } diff --git a/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts b/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts index d75497afa8..94cfc145ac 100644 --- a/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts +++ b/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts @@ -58,7 +58,7 @@ export class QueryEditorService implements IQueryEditorService { // Create a sql document pane with accoutrements const mode = this._connectionManagementService.getProviderLanguageMode(connectionProviderName); - const fileInput = this._editorService.createEditorInput({ forceUntitled: true, resource: docUri, mode: mode }) as UntitledTextEditorInput; + const fileInput = await this._editorService.createEditorInput({ forceUntitled: true, resource: docUri, mode: mode }) as UntitledTextEditorInput; let untitledEditorModel = await fileInput.resolve(); if (options.initalContent) { untitledEditorModel.textEditorModel.setValue(options.initalContent); @@ -102,7 +102,7 @@ export class QueryEditorService implements IQueryEditorService { let docUri: URI = URI.from({ scheme: Schemas.untitled, path: filePath }); // Create a sql document pane with accoutrements - const fileInput = this._editorService.createEditorInput({ forceUntitled: true, resource: docUri, mode: 'sql' }) as UntitledTextEditorInput; + const fileInput = await this._editorService.createEditorInput({ forceUntitled: true, resource: docUri, mode: 'sql' }) as UntitledTextEditorInput; const m = await fileInput.resolve(); //when associatedResource editor is created it is dirty, this must be set to false to be able to detect changes to the editor. (m as UntitledTextEditorModel).setDirty(false); diff --git a/src/sql/workbench/services/queryEditor/test/browser/testQueryEditorService.ts b/src/sql/workbench/services/queryEditor/test/browser/testQueryEditorService.ts index f58f9f8bbb..abbcb133da 100644 --- a/src/sql/workbench/services/queryEditor/test/browser/testQueryEditorService.ts +++ b/src/sql/workbench/services/queryEditor/test/browser/testQueryEditorService.ts @@ -20,8 +20,8 @@ export class TestQueryEditorService implements IQueryEditorService { @IEditorService private readonly editorService: IEditorService) { } - newSqlEditor(options?: INewSqlEditorOptions): Promise { - const base = this.editorService.createEditorInput({ resource: undefined, forceUntitled: true }) as UntitledTextEditorInput; + async newSqlEditor(options?: INewSqlEditorOptions): Promise { + const base = await this.editorService.createEditorInput({ resource: undefined, forceUntitled: true }) as UntitledTextEditorInput; return Promise.resolve(this.instantiationService.createInstance(UntitledQueryEditorInput, '', base, new QueryResultsInput(base.resource.toString(true)))); } diff --git a/src/vs/workbench/services/editor/browser/editorService.ts b/src/vs/workbench/services/editor/browser/editorService.ts index a00c374cc3..eff8ae33e6 100644 --- a/src/vs/workbench/services/editor/browser/editorService.ts +++ b/src/vs/workbench/services/editor/browser/editorService.ts @@ -861,7 +861,7 @@ export class EditorService extends Disposable implements EditorServiceImpl { // {{SQL CARBON EDIT}} -- add back createEditorInput until we can remove all references private readonly editorInputCache = new ResourceMap(); - createEditorInput(input: EditorInput | IUntypedEditorInput): EditorInput { + async createEditorInput(input: EditorInput | IUntypedEditorInput): Promise { // Typed Editor Input Support (EditorInput) if (input instanceof EditorInput) { @@ -873,8 +873,8 @@ export class EditorService extends Disposable implements EditorServiceImpl { // const original = this.createEditorInput({ ...input.original, forceFile: true /*input.forceFile*/ }); // const modified = this.createEditorInput({ ...input.modified, forceFile: true /*input.forceFile*/ }); - const original = this.createEditorInput(input.original); - const modified = this.createEditorInput(input.modified); + const original = await this.createEditorInput(input.original); + const modified = await this.createEditorInput(input.modified); return this.instantiationService.createInstance(DiffEditorInput, input.label, @@ -905,7 +905,7 @@ export class EditorService extends Disposable implements EditorServiceImpl { untitledModel = this.untitledTextEditorService.create({ associatedResource: untitledInput.resource, ...untitledOptions }); } - return this.createOrGetCached(untitledModel.resource, () => { + return this.createOrGetCached(untitledModel.resource, async () => { // Factory function for new untitled editor const input = this.instantiationService.createInstance(UntitledTextEditorInput, untitledModel); @@ -918,7 +918,7 @@ export class EditorService extends Disposable implements EditorServiceImpl { Event.once(input.onWillDispose)(() => untitledModel.dispose()); return input; - }) as EditorInput; + }) as Promise; } // Text Resource Editor Support @@ -937,11 +937,11 @@ export class EditorService extends Disposable implements EditorServiceImpl { // with different resource forms (e.g. path casing on Windows) const canonicalResource = this.uriIdentityService.asCanonicalUri(preferredResource); - return this.createOrGetCached(canonicalResource, () => { + return this.createOrGetCached(canonicalResource, async () => { // File //if (textResourceEditorInput.forceFile || this.fileService.canHandleResource(canonicalResource)) { - if (this.fileService.canHandleResource(canonicalResource)) { + if (await this.fileService.canHandleResource(canonicalResource)) { return this.fileEditorFactory.createFileEditor(canonicalResource, preferredResource, textResourceEditorInput.label, textResourceEditorInput.description, textResourceEditorInput.encoding, textResourceEditorInput.mode, textResourceEditorInput.contents, this.instantiationService); } @@ -997,13 +997,13 @@ export class EditorService extends Disposable implements EditorServiceImpl { cachedInput.setPreferredContents(textResourceEditorInput.contents); } } - }) as EditorInput; + }) as Promise; } throw new Error('Unknown input type'); } - private createOrGetCached(resource: URI, factoryFn: () => CachedEditorInput, cachedFn?: (input: CachedEditorInput) => void): CachedEditorInput { + private async createOrGetCached(resource: URI, factoryFn: () => Promise, cachedFn?: (input: CachedEditorInput) => void): Promise { // Return early if already cached let input = this.editorInputCache.get(resource); @@ -1016,7 +1016,7 @@ export class EditorService extends Disposable implements EditorServiceImpl { } // Otherwise create and add to cache - input = factoryFn(); + input = await factoryFn(); this.editorInputCache.set(resource, input); Event.once(input.onWillDispose)(() => this.editorInputCache.delete(resource)); diff --git a/src/vs/workbench/services/editor/common/editorService.ts b/src/vs/workbench/services/editor/common/editorService.ts index b6013c3c5d..3e46ed031c 100644 --- a/src/vs/workbench/services/editor/common/editorService.ts +++ b/src/vs/workbench/services/editor/common/editorService.ts @@ -259,10 +259,11 @@ export interface IEditorService { findEditors(resource: URI, group: IEditorGroup | GroupIdentifier): readonly EditorInput[]; findEditors(editor: IResourceEditorInputIdentifier, group: IEditorGroup | GroupIdentifier): EditorInput | undefined; + // {{SQL CARBON EDIT}} -- add back createEditorInput until we can remove all references. Make async to handle updated canHandleResource function returning promise /** * Converts a lightweight input to a workbench editor input. */ - createEditorInput(input: IUntypedEditorInput): EditorInput; + createEditorInput(input: IUntypedEditorInput): Promise; /** diff --git a/src/vs/workbench/test/browser/workbenchTestServices.ts b/src/vs/workbench/test/browser/workbenchTestServices.ts index 5351705c39..fdfd087408 100644 --- a/src/vs/workbench/test/browser/workbenchTestServices.ts +++ b/src/vs/workbench/test/browser/workbenchTestServices.ts @@ -917,7 +917,7 @@ export class TestEditorService implements EditorServiceImpl { revert(editors: IEditorIdentifier[], options?: IRevertOptions): Promise { throw new Error('Method not implemented.'); } revertAll(options?: IRevertAllEditorsOptions): Promise { throw new Error('Method not implemented.'); } // {{SQL CARBON EDIT}} add createEditorInput back - createEditorInput(input: IUntypedEditorInput): EditorInput { throw new Error('Method not implemented.'); } + createEditorInput(input: IUntypedEditorInput): Promise { throw new Error('Method not implemented.'); } } export class TestFileService implements IFileService {