diff --git a/src/sql/workbench/parts/query/browser/queryActions.ts b/src/sql/workbench/parts/query/browser/queryActions.ts index 1ab7e7ffc4..81efca7d1c 100644 --- a/src/sql/workbench/parts/query/browser/queryActions.ts +++ b/src/sql/workbench/parts/query/browser/queryActions.ts @@ -167,24 +167,23 @@ export const DE_NEW_QUERY_COMMAND_ID = 'dataExplorer.newQuery'; // New Query CommandsRegistry.registerCommand({ id: DE_NEW_QUERY_COMMAND_ID, - handler: (accessor, args: TreeViewItemHandleArg) => { + handler: async (accessor, args: TreeViewItemHandleArg) => { if (args.$treeItem) { const queryEditorService = accessor.get(IQueryEditorService); const connectionService = accessor.get(IConnectionManagementService); const capabilitiesService = accessor.get(ICapabilitiesService); - return queryEditorService.newSqlEditor().then((owner: IConnectableInput) => { - // Connect our editor to the input connection - let options: IConnectionCompletionOptions = { - params: { connectionType: ConnectionType.editor, input: owner }, - saveTheConnection: false, - showDashboard: false, - showConnectionDialogOnError: true, - showFirewallRuleOnError: true - }; - return connectionService.connect(new ConnectionProfile(capabilitiesService, args.$treeItem.payload), owner.uri, options); - }); + const owner = await queryEditorService.newSqlEditor(); + // Connect our editor to the input connection + let options: IConnectionCompletionOptions = { + params: { connectionType: ConnectionType.editor, input: owner }, + saveTheConnection: false, + showDashboard: false, + showConnectionDialogOnError: true, + showFirewallRuleOnError: true + }; + return connectionService.connect(new ConnectionProfile(capabilitiesService, args.$treeItem.payload), owner.uri, options); } - return Promise.resolve(true); + return true; } }); @@ -205,7 +204,7 @@ export class RunQueryAction extends QueryTaskbarAction { this.label = nls.localize('runQueryLabel', "Run"); } - public run(): Promise { + public async run(): Promise { if (!this.editor.isSelectionEmpty()) { if (this.isConnected(this.editor)) { // If we are already connected, run the query @@ -216,10 +215,10 @@ export class RunQueryAction extends QueryTaskbarAction { this.connectEditor(this.editor, RunQueryOnConnectionMode.executeQuery, this.editor.getSelection()); } } - return Promise.resolve(null); + return; } - public runCurrent(): Promise { + public async runCurrent(): Promise { if (!this.editor.isSelectionEmpty()) { if (this.isConnected(this.editor)) { // If we are already connected, run the query @@ -230,7 +229,7 @@ export class RunQueryAction extends QueryTaskbarAction { this.connectEditor(this.editor, RunQueryOnConnectionMode.executeCurrentQuery, this.editor.getSelection(false)); } } - return Promise.resolve(null); + return; } public runQuery(editor: QueryEditor, runCurrentStatement: boolean = false) { @@ -276,11 +275,14 @@ export class CancelQueryAction extends QueryTaskbarAction { this.label = nls.localize('cancelQueryLabel', "Cancel"); } - public run(): Promise { + public async run(): Promise { if (this.isConnected(this.editor)) { + if (!this.editor.input) { + console.error('editor input was null'); + return; + } this.queryModelService.cancelQuery(this.editor.input.uri); } - return Promise.resolve(null); } } @@ -300,7 +302,7 @@ export class EstimatedQueryPlanAction extends QueryTaskbarAction { this.label = nls.localize('estimatedQueryPlan', "Explain"); } - public run(): Promise { + public async run(): Promise { if (!this.editor.isSelectionEmpty()) { if (this.isConnected(this.editor)) { // If we are already connected, run the query @@ -311,7 +313,7 @@ export class EstimatedQueryPlanAction extends QueryTaskbarAction { this.connectEditor(this.editor, RunQueryOnConnectionMode.estimatedQueryPlan, this.editor.getSelection()); } } - return Promise.resolve(null); + return; } public runQuery(editor: QueryEditor) { @@ -339,7 +341,7 @@ export class ActualQueryPlanAction extends QueryTaskbarAction { this.label = nls.localize('actualQueryPlan', "Actual"); } - public run(): Promise { + public async run(): Promise { if (!this.editor.isSelectionEmpty()) { if (this.isConnected(this.editor)) { // If we are already connected, run the query @@ -350,7 +352,7 @@ export class ActualQueryPlanAction extends QueryTaskbarAction { this.connectEditor(this.editor, RunQueryOnConnectionMode.actualQueryPlan, this.editor.getSelection()); } } - return Promise.resolve(null); + return; } public runQuery(editor: QueryEditor) { @@ -386,11 +388,11 @@ export class DisconnectDatabaseAction extends QueryTaskbarAction { this.label = nls.localize('disconnectDatabaseLabel', "Disconnect"); } - public run(): Promise { + public async run(): Promise { // Call disconnectEditor regardless of the connection state and let the ConnectionManagementService // determine if we need to disconnect, cancel an in-progress conneciton, or do nothing this.connectionManagementService.disconnectEditor(this.editor.input); - return Promise.resolve(null); + return; } } @@ -424,9 +426,9 @@ export class ConnectDatabaseAction extends QueryTaskbarAction { this.label = label; } - public run(): Promise { + public async run(): Promise { this.connectEditor(this.editor); - return Promise.resolve(null); + return; } } @@ -471,7 +473,8 @@ export class ToggleConnectDatabaseAction extends QueryTaskbarAction { } } - public run(): Promise { + + public async run(): Promise { if (!this.editor.input.isSharedSession) { if (this.connected) { // Call disconnectEditor regardless of the connection state and let the ConnectionManagementService @@ -481,7 +484,7 @@ export class ToggleConnectDatabaseAction extends QueryTaskbarAction { this.connectEditor(this.editor); } } - return Promise.resolve(null); + return; } } @@ -502,8 +505,8 @@ export class ListDatabasesAction extends QueryTaskbarAction { this.class = ListDatabasesAction.EnabledClass; } - public run(): Promise { - return Promise.resolve(null); + public async run(): Promise { + return; } } @@ -547,18 +550,21 @@ export class ToggleSqlCmdModeAction extends QueryTaskbarAction { } - public run(): Promise { + public async run(): Promise { const toSqlCmdState = !this.isSqlCmdMode; // input.state change triggers event that changes this.isSqlCmdMode, so store it before using this.editor.input.state.isSqlCmdMode = toSqlCmdState; // set query options let queryoptions: QueryExecutionOptions = { options: new Map() }; queryoptions.options['isSqlCmdMode'] = toSqlCmdState; + if (!this.editor.input) { + console.error('editor input was null'); + return; + } this.queryManagementService.setQueryExecutionOptions(this.editor.input.uri, queryoptions); // set intellisense options toSqlCmdState ? this.connectionManagementService.doChangeLanguageFlavor(this.editor.input.uri, 'sqlcmd', 'MSSQL') : this.connectionManagementService.doChangeLanguageFlavor(this.editor.input.uri, 'sql', 'MSSQL'); - return Promise.resolve(null); } } @@ -677,6 +683,11 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt // PRIVATE HELPERS ///////////////////////////////////////////////////// private databaseSelected(dbName: string): void { + if (!this._editor.input) { + console.error('editor input was null'); + return; + } + let uri = this._editor.input.uri; if (!uri) { return; @@ -707,7 +718,12 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt }); } - private getCurrentDatabaseName() { + private getCurrentDatabaseName(): string | undefined { + if (!this._editor.input) { + console.error('editor input was null'); + return undefined; + } + let uri = this._editor.input.uri; if (uri) { let profile = this.connectionManagementService.getConnectionProfile(uri); @@ -731,6 +747,11 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt return; } + if (!this._editor.input) { + console.error('editor input was null'); + return; + } + let uri = this._editor.input.uri; if (uri !== connParams.connectionUri) { return; @@ -740,6 +761,11 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt } private onDropdownFocus(): void { + if (!this._editor.input) { + console.error('editor input was null'); + return; + } + let uri = this._editor.input.uri; if (!uri) { return; @@ -759,6 +785,10 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt if (this._isInAccessibilityMode) { this._databaseSelectBox.enable(); + if (!this._editor.input) { + console.error('editor input was null'); + return; + } let uri = this._editor.input.uri; if (!uri) { return; diff --git a/src/sql/workbench/parts/query/browser/queryEditor.ts b/src/sql/workbench/parts/query/browser/queryEditor.ts index e0e8f99cf1..73a774275a 100644 --- a/src/sql/workbench/parts/query/browser/queryEditor.ts +++ b/src/sql/workbench/parts/query/browser/queryEditor.ts @@ -120,7 +120,7 @@ export class QueryEditor extends BaseEditor { } // PUBLIC METHODS //////////////////////////////////////////////////////////// - public get input(): QueryInput { + public get input(): QueryInput | null { return this._input as QueryInput; }