mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-13 17:22:15 -05:00
Make createEditorInput async (#20038)
This commit is contained in:
@@ -71,7 +71,7 @@ export default class EditorComponent extends ComponentBase<azdata.EditorProperti
|
||||
this._editor.setVisible(true);
|
||||
let uri = this.createUri();
|
||||
|
||||
this._editorInput = this.editorService.createEditorInput({ forceUntitled: true, resource: uri, mode: 'plaintext' }) as UntitledTextEditorInput;
|
||||
this._editorInput = await this.editorService.createEditorInput({ forceUntitled: true, resource: uri, mode: 'plaintext' }) as UntitledTextEditorInput;
|
||||
|
||||
await this._editor.setInput(this._editorInput, undefined, undefined);
|
||||
const model = await this._editorInput.resolve();
|
||||
|
||||
@@ -782,15 +782,15 @@ export class NotebookEditorOverrideContribution extends Disposable implements IW
|
||||
priority: RegisteredEditorPriority.builtin
|
||||
},
|
||||
{},
|
||||
(editorInput, group) => {
|
||||
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 };
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -20,8 +20,8 @@ export class TestQueryEditorService implements IQueryEditorService {
|
||||
@IEditorService private readonly editorService: IEditorService) {
|
||||
}
|
||||
|
||||
newSqlEditor(options?: INewSqlEditorOptions): Promise<IUntitledQueryEditorInput> {
|
||||
const base = this.editorService.createEditorInput({ resource: undefined, forceUntitled: true }) as UntitledTextEditorInput;
|
||||
async newSqlEditor(options?: INewSqlEditorOptions): Promise<IUntitledQueryEditorInput> {
|
||||
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))));
|
||||
}
|
||||
|
||||
|
||||
@@ -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<CachedEditorInput>();
|
||||
|
||||
createEditorInput(input: EditorInput | IUntypedEditorInput): EditorInput {
|
||||
async createEditorInput(input: EditorInput | IUntypedEditorInput): Promise<EditorInput> {
|
||||
|
||||
// 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<EditorInput>;
|
||||
}
|
||||
|
||||
// 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<EditorInput>;
|
||||
}
|
||||
|
||||
throw new Error('Unknown input type');
|
||||
}
|
||||
|
||||
private createOrGetCached(resource: URI, factoryFn: () => CachedEditorInput, cachedFn?: (input: CachedEditorInput) => void): CachedEditorInput {
|
||||
private async createOrGetCached(resource: URI, factoryFn: () => Promise<CachedEditorInput>, cachedFn?: (input: CachedEditorInput) => void): Promise<CachedEditorInput> {
|
||||
|
||||
// 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));
|
||||
|
||||
|
||||
@@ -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<EditorInput>;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -917,7 +917,7 @@ export class TestEditorService implements EditorServiceImpl {
|
||||
revert(editors: IEditorIdentifier[], options?: IRevertOptions): Promise<boolean> { throw new Error('Method not implemented.'); }
|
||||
revertAll(options?: IRevertAllEditorsOptions): Promise<boolean> { 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<EditorInput> { throw new Error('Method not implemented.'); }
|
||||
}
|
||||
|
||||
export class TestFileService implements IFileService {
|
||||
|
||||
Reference in New Issue
Block a user