diff --git a/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts b/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts index a607157180..f51456c539 100644 --- a/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts +++ b/src/sql/workbench/services/queryEditor/browser/queryEditorService.ts @@ -99,44 +99,32 @@ export class QueryEditorService implements IQueryEditorService { /** * Creates new edit data session */ - public newEditDataEditor(schemaName: string, tableName: string, sqlContent: string): Promise { + public async newEditDataEditor(schemaName: string, tableName: string, sqlContent: string): Promise { - return new Promise(async (resolve, reject) => { - try { - // Create file path and file URI - let objectName = schemaName ? schemaName + '.' + tableName : tableName; - let filePath = await this.createPrefixedSqlFilePath(objectName); - let docUri: URI = URI.from({ scheme: Schemas.untitled, path: filePath }); + // Create file path and file URI + let objectName = schemaName ? schemaName + '.' + tableName : tableName; + let filePath = await this.createPrefixedSqlFilePath(objectName); + let docUri: URI = URI.from({ scheme: Schemas.untitled, path: filePath }); - // Create a sql document pane with accoutrements - const fileInput = this._untitledEditorService.createOrGet(docUri, 'sql'); - fileInput.resolve().then(m => { - if (sqlContent) { - m.textEditorModel.setValue(sqlContent); - } - }); + // Create a sql document pane with accoutrements + const fileInput = this._untitledEditorService.createOrGet(docUri, 'sql'); + const m = await fileInput.resolve(); + if (sqlContent) { + m.textEditorModel.setValue(sqlContent); + } - // Create an EditDataInput for editing - const resultsInput: EditDataResultsInput = this._instantiationService.createInstance(EditDataResultsInput, docUri.toString()); - let editDataInput: EditDataInput = this._instantiationService.createInstance(EditDataInput, docUri, schemaName, tableName, fileInput, sqlContent, resultsInput); + // Create an EditDataInput for editing + const resultsInput: EditDataResultsInput = this._instantiationService.createInstance(EditDataResultsInput, docUri.toString()); + let editDataInput: EditDataInput = this._instantiationService.createInstance(EditDataInput, docUri, schemaName, tableName, fileInput, sqlContent, resultsInput); - this._editorService.openEditor(editDataInput, { pinned: true }) - .then((editor) => { - let params = editor.input; - resolve(params); - }, (error) => { - reject(error); - }); - } catch (error) { - reject(error); - } - }); + const editor = await this._editorService.openEditor(editDataInput, { pinned: true }); + let params = editor.input as EditDataInput; + return params; } onSaveAsCompleted(oldResource: URI, newResource: URI): void { let oldResourceString: string = oldResource.toString(); - this._editorService.editors.forEach(input => { if (input instanceof QueryInput) { const resource = input.getResource(); @@ -174,9 +162,9 @@ export class QueryEditorService implements IQueryEditorService { * In all other cases (when SQL is involved in the language change and the editor is not dirty), * returns a promise that will resolve when the old editor has been replaced by a new editor. */ - public sqlLanguageModeCheck(model: ITextModel, languageSelection: ILanguageSelection, editor: IEditor): Promise { + public async sqlLanguageModeCheck(model: ITextModel, languageSelection: ILanguageSelection, editor: IEditor): Promise { if (!model || !languageSelection || !editor) { - return Promise.resolve(undefined); + return undefined; } let newLanguage: string = languageSelection.languageIdentifier.language; @@ -186,10 +174,10 @@ export class QueryEditorService implements IQueryEditorService { let changingLanguage = newLanguage !== oldLanguage; if (!changingLanguage) { - return Promise.resolve(model); + return model; } if (!changingFromSql && !changingToSql) { - return Promise.resolve(model); + return model; } let uri: URI = QueryEditorService._getEditorChangeUri(editor.input, changingToSql); @@ -198,7 +186,7 @@ export class QueryEditorService implements IQueryEditorService { severity: Severity.Error, message: QueryEditorService.CHANGE_UNSUPPORTED_ERROR_MESSAGE }); - return Promise.resolve(undefined); + return undefined; } // Return undefined to notify the calling funciton to not perform the language change @@ -208,7 +196,7 @@ export class QueryEditorService implements IQueryEditorService { severity: Severity.Error, message: QueryEditorService.CHANGE_ERROR_MESSAGE }); - return Promise.resolve(undefined); + return undefined; } let group: IEditorGroup = editor.group; @@ -217,24 +205,18 @@ export class QueryEditorService implements IQueryEditorService { options = Object.assign(options, { index: index }); // Return a promise that will resovle when the old editor has been replaced by a new editor - return new Promise((resolve, reject) => { - let newEditorInput = this.getNewEditorInput(changingToSql, editor.input, uri); + let newEditorInput = this.getNewEditorInput(changingToSql, editor.input, uri); - // Override queryEditorCheck to not open this file in a QueryEditor - if (!changingToSql) { - options.denyQueryEditor = true; - } + // Override queryEditorCheck to not open this file in a QueryEditor + if (!changingToSql) { + options.denyQueryEditor = true; + } - group.closeEditor(editor.input).then(() => { - // Reopen a new editor in the same position/index - this._editorService.openEditor(newEditorInput, options, group).then((editor) => { - resolve(QueryEditorService._onEditorOpened(editor, uri.toString(), undefined, options.pinned)); - }, - (error) => { - reject(error); - }); - }); - }); + await group.closeEditor(editor.input); + // Reopen a new editor in the same position/index + const newEditor = await this._editorService.openEditor(newEditorInput, options, group); + + return QueryEditorService._onEditorOpened(newEditor, uri.toString(), undefined, options.pinned); } ////// Private functions