mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-16 17:22:29 -05:00
More promise cleanup (#8100)
* Some promise cleanup * Handle more promise issues * Remove changes that aren't needed anymore * Use log service * another one * Be more explicit * Some more promises cleaned up * Handle promises here too * Strings for errors * Some more cleanup * Remove unused imports
This commit is contained in:
@@ -23,6 +23,7 @@ import { QueryTextEditor } from 'sql/workbench/browser/modelComponents/queryText
|
||||
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
|
||||
import { SimpleEditorProgressService } from 'vs/editor/standalone/browser/simpleServices';
|
||||
import { IProgressService } from 'vs/platform/progress/common/progress';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
|
||||
@Component({
|
||||
template: '',
|
||||
@@ -45,33 +46,33 @@ export default class EditorComponent extends ComponentBase implements IComponent
|
||||
@Inject(forwardRef(() => ElementRef)) el: ElementRef,
|
||||
@Inject(IInstantiationService) private _instantiationService: IInstantiationService,
|
||||
@Inject(IModelService) private _modelService: IModelService,
|
||||
@Inject(IModeService) private _modeService: IModeService
|
||||
@Inject(IModeService) private _modeService: IModeService,
|
||||
@Inject(ILogService) private _logService: ILogService
|
||||
) {
|
||||
super(changeRef, el);
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.baseInit();
|
||||
this._createEditor();
|
||||
this._createEditor().catch((e) => this._logService.error(e));
|
||||
this._register(DOM.addDisposableListener(window, DOM.EventType.RESIZE, e => {
|
||||
this.layout();
|
||||
}));
|
||||
}
|
||||
|
||||
private _createEditor(): void {
|
||||
private async _createEditor(): Promise<void> {
|
||||
let instantiationService = this._instantiationService.createChild(new ServiceCollection([IProgressService, new SimpleEditorProgressService()]));
|
||||
this._editor = instantiationService.createInstance(QueryTextEditor);
|
||||
this._editor.create(this._el.nativeElement);
|
||||
this._editor.setVisible(true);
|
||||
let uri = this.createUri();
|
||||
this._editorInput = instantiationService.createInstance(UntitledEditorInput, uri, false, 'plaintext', '', '');
|
||||
this._editor.setInput(this._editorInput, undefined);
|
||||
this._editorInput.resolve().then(model => {
|
||||
this._editorModel = model.textEditorModel;
|
||||
this.fireEvent({
|
||||
eventType: ComponentEventType.onComponentCreated,
|
||||
args: this._uri
|
||||
});
|
||||
await this._editor.setInput(this._editorInput, undefined);
|
||||
const model = await this._editorInput.resolve();
|
||||
this._editorModel = model.textEditorModel;
|
||||
this.fireEvent({
|
||||
eventType: ComponentEventType.onComponentCreated,
|
||||
args: this._uri
|
||||
});
|
||||
|
||||
this._register(this._editor);
|
||||
|
||||
@@ -25,14 +25,14 @@ export class ScriptSelectAction extends Action {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
public run(actionContext: BaseActionContext): Promise<boolean> {
|
||||
public async run(actionContext: BaseActionContext): Promise<boolean> {
|
||||
return scriptSelect(
|
||||
actionContext.profile,
|
||||
actionContext.object,
|
||||
this._connectionManagementService,
|
||||
this._queryEditorService,
|
||||
this._scriptingService
|
||||
).then(() => true);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ export class ScriptExecuteAction extends Action {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
public run(actionContext: BaseActionContext): Promise<boolean> {
|
||||
public async run(actionContext: BaseActionContext): Promise<boolean> {
|
||||
return script(
|
||||
actionContext.profile,
|
||||
actionContext.object,
|
||||
@@ -59,7 +59,7 @@ export class ScriptExecuteAction extends Action {
|
||||
this._scriptingService,
|
||||
ScriptOperation.Execute,
|
||||
this._errorMessageService
|
||||
).then(() => true);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ export class ScriptAlterAction extends Action {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
public run(actionContext: BaseActionContext): Promise<boolean> {
|
||||
public async run(actionContext: BaseActionContext): Promise<boolean> {
|
||||
return script(
|
||||
actionContext.profile,
|
||||
actionContext.object,
|
||||
@@ -86,7 +86,7 @@ export class ScriptAlterAction extends Action {
|
||||
this._scriptingService,
|
||||
ScriptOperation.Alter,
|
||||
this._errorMessageService
|
||||
).then(() => true);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,14 +103,14 @@ export class EditDataAction extends Action {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
public run(actionContext: BaseActionContext): Promise<boolean> {
|
||||
public async run(actionContext: BaseActionContext): Promise<boolean> {
|
||||
return scriptEditSelect(
|
||||
actionContext.profile,
|
||||
actionContext.object,
|
||||
this._connectionManagementService,
|
||||
this._queryEditorService,
|
||||
this._scriptingService
|
||||
).then(() => true);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ export class ScriptCreateAction extends Action {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
public run(actionContext: BaseActionContext): Promise<boolean> {
|
||||
public async run(actionContext: BaseActionContext): Promise<boolean> {
|
||||
return script(
|
||||
actionContext.profile,
|
||||
actionContext.object,
|
||||
@@ -137,7 +137,7 @@ export class ScriptCreateAction extends Action {
|
||||
this._scriptingService,
|
||||
ScriptOperation.Create,
|
||||
this._errorMessageService
|
||||
).then(() => true);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ export class ScriptDeleteAction extends Action {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
public run(actionContext: BaseActionContext): Promise<boolean> {
|
||||
public async run(actionContext: BaseActionContext): Promise<boolean> {
|
||||
return script(
|
||||
actionContext.profile,
|
||||
actionContext.object,
|
||||
@@ -164,6 +164,6 @@ export class ScriptDeleteAction extends Action {
|
||||
this._scriptingService,
|
||||
ScriptOperation.Delete,
|
||||
this._errorMessageService
|
||||
).then(() => true);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import { IConnectionManagementService, IConnectionCompletionOptions, ConnectionType, IConnectableInput, RunQueryOnConnectionMode } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { IConnectionManagementService, IConnectionCompletionOptions, ConnectionType, RunQueryOnConnectionMode } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { ConnectionManagementInfo } from 'sql/platform/connection/common/connectionManagementInfo';
|
||||
import * as nls from 'vs/nls';
|
||||
import Severity from 'vs/base/common/severity';
|
||||
@@ -12,7 +12,6 @@ import { IErrorMessageService } from 'sql/platform/errorMessage/common/errorMess
|
||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
import { IQueryEditorService } from 'sql/workbench/services/queryEditor/common/queryEditorService';
|
||||
import { IScriptingService, ScriptOperation } from 'sql/platform/scripting/common/scriptingService';
|
||||
import { EditDataInput } from 'sql/workbench/parts/editData/browser/editDataInput';
|
||||
|
||||
// map for the version of SQL Server (default is 140)
|
||||
const scriptCompatibilityOptionMap = {
|
||||
@@ -41,71 +40,53 @@ const targetDatabaseEngineEditionMap = {
|
||||
/**
|
||||
* Select the top rows from an object
|
||||
*/
|
||||
export function scriptSelect(connectionProfile: IConnectionProfile, metadata: azdata.ObjectMetadata, connectionService: IConnectionManagementService, queryEditorService: IQueryEditorService, scriptingService: IScriptingService): Promise<void> {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
connectionService.connectIfNotConnected(connectionProfile).then(connectionResult => {
|
||||
let paramDetails: azdata.ScriptingParamDetails = getScriptingParamDetails(connectionService, connectionResult, metadata);
|
||||
scriptingService.script(connectionResult, metadata, ScriptOperation.Select, paramDetails).then(result => {
|
||||
if (result && result.script) {
|
||||
queryEditorService.newSqlEditor(result.script).then((owner: IConnectableInput) => {
|
||||
// Connect our editor to the input connection
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.executeQuery, input: owner },
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: true,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
connectionService.connect(connectionProfile, owner.uri, options).then(() => {
|
||||
resolve();
|
||||
});
|
||||
}).catch(editorError => {
|
||||
reject(editorError);
|
||||
});
|
||||
} else {
|
||||
let errMsg: string = nls.localize('scriptSelectNotFound', "No script was returned when calling select script on object ");
|
||||
reject(errMsg.concat(metadata.metadataTypeName));
|
||||
}
|
||||
}, scriptError => {
|
||||
reject(scriptError);
|
||||
});
|
||||
});
|
||||
});
|
||||
export async function scriptSelect(connectionProfile: IConnectionProfile, metadata: azdata.ObjectMetadata, connectionService: IConnectionManagementService, queryEditorService: IQueryEditorService, scriptingService: IScriptingService): Promise<boolean> {
|
||||
const connectionResult = await connectionService.connectIfNotConnected(connectionProfile);
|
||||
let paramDetails: azdata.ScriptingParamDetails = getScriptingParamDetails(connectionService, connectionResult, metadata);
|
||||
const result = await scriptingService.script(connectionResult, metadata, ScriptOperation.Select, paramDetails);
|
||||
if (result && result.script) {
|
||||
const owner = await queryEditorService.newSqlEditor(result.script);
|
||||
// Connect our editor to the input connection
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.executeQuery, input: owner },
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: true,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
const innerConnectionResult = await connectionService.connect(connectionProfile, owner.uri, options);
|
||||
|
||||
return Boolean(innerConnectionResult) && innerConnectionResult.connected;
|
||||
} else {
|
||||
let errMsg: string = nls.localize('scriptSelectNotFound', "No script was returned when calling select script on object ");
|
||||
throw new Error(errMsg.concat(metadata.metadataTypeName));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a new Edit Data session
|
||||
*/
|
||||
export function scriptEditSelect(connectionProfile: IConnectionProfile, metadata: azdata.ObjectMetadata, connectionService: IConnectionManagementService, queryEditorService: IQueryEditorService, scriptingService: IScriptingService): Promise<void> {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
connectionService.connectIfNotConnected(connectionProfile).then(connectionResult => {
|
||||
let paramDetails: azdata.ScriptingParamDetails = getScriptingParamDetails(connectionService, connectionResult, metadata);
|
||||
scriptingService.script(connectionResult, metadata, ScriptOperation.Select, paramDetails).then(result => {
|
||||
if (result && result.script) {
|
||||
queryEditorService.newEditDataEditor(metadata.schema, metadata.name, result.script).then((owner: EditDataInput) => {
|
||||
// Connect our editor
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.none, input: owner },
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: true,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
connectionService.connect(connectionProfile, owner.uri, options).then(() => {
|
||||
resolve();
|
||||
});
|
||||
}).catch(editorError => {
|
||||
reject(editorError);
|
||||
});
|
||||
} else {
|
||||
let errMsg: string = nls.localize('scriptSelectNotFound', "No script was returned when calling select script on object ");
|
||||
reject(errMsg.concat(metadata.metadataTypeName));
|
||||
}
|
||||
}, scriptError => {
|
||||
reject(scriptError);
|
||||
});
|
||||
});
|
||||
});
|
||||
export async function scriptEditSelect(connectionProfile: IConnectionProfile, metadata: azdata.ObjectMetadata, connectionService: IConnectionManagementService, queryEditorService: IQueryEditorService, scriptingService: IScriptingService): Promise<boolean> {
|
||||
const connectionResult = await connectionService.connectIfNotConnected(connectionProfile);
|
||||
let paramDetails: azdata.ScriptingParamDetails = getScriptingParamDetails(connectionService, connectionResult, metadata);
|
||||
const result = await scriptingService.script(connectionResult, metadata, ScriptOperation.Select, paramDetails);
|
||||
if (result && result.script) {
|
||||
const owner = await queryEditorService.newEditDataEditor(metadata.schema, metadata.name, result.script);
|
||||
// Connect our editor
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.none, input: owner },
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: true,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
const innerConnectionResult = await connectionService.connect(connectionProfile, owner.uri, options);
|
||||
|
||||
return Boolean(innerConnectionResult) && innerConnectionResult.connected;
|
||||
} else {
|
||||
let errMsg: string = nls.localize('scriptSelectNotFound', "No script was returned when calling select script on object ");
|
||||
throw new Error(errMsg.concat(metadata.metadataTypeName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -132,61 +113,51 @@ export function GetScriptOperationName(operation: ScriptOperation) {
|
||||
/**
|
||||
* Script the object as a statement based on the provided action (except Select)
|
||||
*/
|
||||
export function script(connectionProfile: IConnectionProfile, metadata: azdata.ObjectMetadata,
|
||||
export async function script(connectionProfile: IConnectionProfile, metadata: azdata.ObjectMetadata,
|
||||
connectionService: IConnectionManagementService,
|
||||
queryEditorService: IQueryEditorService,
|
||||
scriptingService: IScriptingService,
|
||||
operation: ScriptOperation,
|
||||
errorMessageService: IErrorMessageService): Promise<void> {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
connectionService.connectIfNotConnected(connectionProfile).then(connectionResult => {
|
||||
let paramDetails = getScriptingParamDetails(connectionService, connectionResult, metadata);
|
||||
scriptingService.script(connectionResult, metadata, operation, paramDetails).then(result => {
|
||||
if (result) {
|
||||
let script: string = result.script;
|
||||
errorMessageService: IErrorMessageService): Promise<boolean> {
|
||||
const connectionResult = await connectionService.connectIfNotConnected(connectionProfile);
|
||||
let paramDetails = getScriptingParamDetails(connectionService, connectionResult, metadata);
|
||||
const result = await scriptingService.script(connectionResult, metadata, operation, paramDetails);
|
||||
if (result) {
|
||||
let script: string = result.script;
|
||||
|
||||
if (script) {
|
||||
let description = (metadata.schema && metadata.schema !== '') ? `${metadata.schema}.${metadata.name}` : metadata.name;
|
||||
queryEditorService.newSqlEditor(script, connectionProfile.providerName, undefined, description).then((owner) => {
|
||||
// Connect our editor to the input connection
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.none, input: owner },
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: true,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
connectionService.connect(connectionProfile, owner.uri, options).then(() => {
|
||||
resolve();
|
||||
});
|
||||
}).catch(editorError => {
|
||||
reject(editorError);
|
||||
});
|
||||
} else {
|
||||
let scriptNotFoundMsg = nls.localize('scriptNotFoundForObject', "No script was returned when scripting as {0} on object {1}",
|
||||
GetScriptOperationName(operation), metadata.metadataTypeName);
|
||||
let messageDetail = '';
|
||||
let operationResult = scriptingService.getOperationFailedResult(result.operationId);
|
||||
if (operationResult && operationResult.hasError && operationResult.errorMessage) {
|
||||
scriptNotFoundMsg = operationResult.errorMessage;
|
||||
messageDetail = operationResult.errorDetails;
|
||||
}
|
||||
if (errorMessageService) {
|
||||
let title = nls.localize('scriptingFailed', "Scripting Failed");
|
||||
errorMessageService.showDialog(Severity.Error, title, scriptNotFoundMsg, messageDetail);
|
||||
}
|
||||
reject(scriptNotFoundMsg);
|
||||
}
|
||||
} else {
|
||||
reject(nls.localize('scriptNotFound', "No script was returned when scripting as {0}", GetScriptOperationName(operation)));
|
||||
}
|
||||
}, scriptingError => {
|
||||
reject(scriptingError);
|
||||
});
|
||||
}).catch(connectionError => {
|
||||
reject(connectionError);
|
||||
});
|
||||
});
|
||||
if (script) {
|
||||
let description = (metadata.schema && metadata.schema !== '') ? `${metadata.schema}.${metadata.name}` : metadata.name;
|
||||
const owner = await queryEditorService.newSqlEditor(script, connectionProfile.providerName, undefined, description);
|
||||
// Connect our editor to the input connection
|
||||
let options: IConnectionCompletionOptions = {
|
||||
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.none, input: owner },
|
||||
saveTheConnection: false,
|
||||
showDashboard: false,
|
||||
showConnectionDialogOnError: true,
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
const innerConnectionResult = await connectionService.connect(connectionProfile, owner.uri, options);
|
||||
|
||||
return Boolean(innerConnectionResult) && innerConnectionResult.connected;
|
||||
|
||||
} else {
|
||||
let scriptNotFoundMsg = nls.localize('scriptNotFoundForObject', "No script was returned when scripting as {0} on object {1}",
|
||||
GetScriptOperationName(operation), metadata.metadataTypeName);
|
||||
let messageDetail = '';
|
||||
let operationResult = scriptingService.getOperationFailedResult(result.operationId);
|
||||
if (operationResult && operationResult.hasError && operationResult.errorMessage) {
|
||||
scriptNotFoundMsg = operationResult.errorMessage;
|
||||
messageDetail = operationResult.errorDetails;
|
||||
}
|
||||
if (errorMessageService) {
|
||||
let title = nls.localize('scriptingFailed', "Scripting Failed");
|
||||
errorMessageService.showDialog(Severity.Error, title, scriptNotFoundMsg, messageDetail);
|
||||
}
|
||||
throw new Error(scriptNotFoundMsg);
|
||||
}
|
||||
} else {
|
||||
throw new Error(nls.localize('scriptNotFound', "No script was returned when scripting as {0}", GetScriptOperationName(operation)));
|
||||
}
|
||||
}
|
||||
|
||||
function getScriptingParamDetails(connectionService: IConnectionManagementService, ownerUri: string, metadata: azdata.ObjectMetadata): azdata.ScriptingParamDetails {
|
||||
|
||||
Reference in New Issue
Block a user