mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 11:01:37 -05:00
cleanup promises and async (#7169)
This commit is contained in:
@@ -99,10 +99,8 @@ export class QueryEditorService implements IQueryEditorService {
|
|||||||
/**
|
/**
|
||||||
* Creates new edit data session
|
* Creates new edit data session
|
||||||
*/
|
*/
|
||||||
public newEditDataEditor(schemaName: string, tableName: string, sqlContent: string): Promise<IConnectableInput> {
|
public async newEditDataEditor(schemaName: string, tableName: string, sqlContent: string): Promise<IConnectableInput> {
|
||||||
|
|
||||||
return new Promise<IConnectableInput>(async (resolve, reject) => {
|
|
||||||
try {
|
|
||||||
// Create file path and file URI
|
// Create file path and file URI
|
||||||
let objectName = schemaName ? schemaName + '.' + tableName : tableName;
|
let objectName = schemaName ? schemaName + '.' + tableName : tableName;
|
||||||
let filePath = await this.createPrefixedSqlFilePath(objectName);
|
let filePath = await this.createPrefixedSqlFilePath(objectName);
|
||||||
@@ -110,33 +108,23 @@ export class QueryEditorService implements IQueryEditorService {
|
|||||||
|
|
||||||
// Create a sql document pane with accoutrements
|
// Create a sql document pane with accoutrements
|
||||||
const fileInput = this._untitledEditorService.createOrGet(docUri, 'sql');
|
const fileInput = this._untitledEditorService.createOrGet(docUri, 'sql');
|
||||||
fileInput.resolve().then(m => {
|
const m = await fileInput.resolve();
|
||||||
if (sqlContent) {
|
if (sqlContent) {
|
||||||
m.textEditorModel.setValue(sqlContent);
|
m.textEditorModel.setValue(sqlContent);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
// Create an EditDataInput for editing
|
// Create an EditDataInput for editing
|
||||||
const resultsInput: EditDataResultsInput = this._instantiationService.createInstance(EditDataResultsInput, docUri.toString());
|
const resultsInput: EditDataResultsInput = this._instantiationService.createInstance(EditDataResultsInput, docUri.toString());
|
||||||
let editDataInput: EditDataInput = this._instantiationService.createInstance(EditDataInput, docUri, schemaName, tableName, fileInput, sqlContent, resultsInput);
|
let editDataInput: EditDataInput = this._instantiationService.createInstance(EditDataInput, docUri, schemaName, tableName, fileInput, sqlContent, resultsInput);
|
||||||
|
|
||||||
this._editorService.openEditor(editDataInput, { pinned: true })
|
const editor = await this._editorService.openEditor(editDataInput, { pinned: true });
|
||||||
.then((editor) => {
|
let params = editor.input as EditDataInput;
|
||||||
let params = <EditDataInput>editor.input;
|
return params;
|
||||||
resolve(params);
|
|
||||||
}, (error) => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
reject(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onSaveAsCompleted(oldResource: URI, newResource: URI): void {
|
onSaveAsCompleted(oldResource: URI, newResource: URI): void {
|
||||||
let oldResourceString: string = oldResource.toString();
|
let oldResourceString: string = oldResource.toString();
|
||||||
|
|
||||||
|
|
||||||
this._editorService.editors.forEach(input => {
|
this._editorService.editors.forEach(input => {
|
||||||
if (input instanceof QueryInput) {
|
if (input instanceof QueryInput) {
|
||||||
const resource = input.getResource();
|
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),
|
* 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.
|
* 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<ITextModel> {
|
public async sqlLanguageModeCheck(model: ITextModel, languageSelection: ILanguageSelection, editor: IEditor): Promise<ITextModel> {
|
||||||
if (!model || !languageSelection || !editor) {
|
if (!model || !languageSelection || !editor) {
|
||||||
return Promise.resolve(undefined);
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
let newLanguage: string = languageSelection.languageIdentifier.language;
|
let newLanguage: string = languageSelection.languageIdentifier.language;
|
||||||
@@ -186,10 +174,10 @@ export class QueryEditorService implements IQueryEditorService {
|
|||||||
let changingLanguage = newLanguage !== oldLanguage;
|
let changingLanguage = newLanguage !== oldLanguage;
|
||||||
|
|
||||||
if (!changingLanguage) {
|
if (!changingLanguage) {
|
||||||
return Promise.resolve(model);
|
return model;
|
||||||
}
|
}
|
||||||
if (!changingFromSql && !changingToSql) {
|
if (!changingFromSql && !changingToSql) {
|
||||||
return Promise.resolve(model);
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
let uri: URI = QueryEditorService._getEditorChangeUri(editor.input, changingToSql);
|
let uri: URI = QueryEditorService._getEditorChangeUri(editor.input, changingToSql);
|
||||||
@@ -198,7 +186,7 @@ export class QueryEditorService implements IQueryEditorService {
|
|||||||
severity: Severity.Error,
|
severity: Severity.Error,
|
||||||
message: QueryEditorService.CHANGE_UNSUPPORTED_ERROR_MESSAGE
|
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
|
// 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,
|
severity: Severity.Error,
|
||||||
message: QueryEditorService.CHANGE_ERROR_MESSAGE
|
message: QueryEditorService.CHANGE_ERROR_MESSAGE
|
||||||
});
|
});
|
||||||
return Promise.resolve(undefined);
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
let group: IEditorGroup = editor.group;
|
let group: IEditorGroup = editor.group;
|
||||||
@@ -217,7 +205,6 @@ export class QueryEditorService implements IQueryEditorService {
|
|||||||
options = Object.assign(options, { index: index });
|
options = Object.assign(options, { index: index });
|
||||||
|
|
||||||
// Return a promise that will resovle when the old editor has been replaced by a new editor
|
// Return a promise that will resovle when the old editor has been replaced by a new editor
|
||||||
return new Promise<ITextModel>((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
|
// Override queryEditorCheck to not open this file in a QueryEditor
|
||||||
@@ -225,16 +212,11 @@ export class QueryEditorService implements IQueryEditorService {
|
|||||||
options.denyQueryEditor = true;
|
options.denyQueryEditor = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
group.closeEditor(editor.input).then(() => {
|
await group.closeEditor(editor.input);
|
||||||
// Reopen a new editor in the same position/index
|
// Reopen a new editor in the same position/index
|
||||||
this._editorService.openEditor(newEditorInput, options, group).then((editor) => {
|
const newEditor = await this._editorService.openEditor(newEditorInput, options, group);
|
||||||
resolve(QueryEditorService._onEditorOpened(editor, uri.toString(), undefined, options.pinned));
|
|
||||||
},
|
return QueryEditorService._onEditorOpened(newEditor, uri.toString(), undefined, options.pinned);
|
||||||
(error) => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////// Private functions
|
////// Private functions
|
||||||
|
|||||||
Reference in New Issue
Block a user