Feature/sqlcmd - ADS changes to enable SQLCMD (#6555)

* Basic SQLCMD functionality to run query and toggle mode

* icons and  some cleanup

* Adding PR comments
This commit is contained in:
Udeesha Gautam
2019-08-20 11:40:16 -07:00
committed by GitHub
parent c513204501
commit 9117b02c72
8 changed files with 147 additions and 3 deletions

View File

@@ -15,7 +15,7 @@ import { IExtensionTipsService } from 'vs/workbench/services/extensionManagement
import Severity from 'vs/base/common/severity';
import { append, $ } from 'vs/base/browser/dom';
import { ISelectionData } from 'azdata';
import { ISelectionData, QueryExecutionOptions } from 'azdata';
import {
IConnectionManagementService,
IConnectionParams,
@@ -28,6 +28,7 @@ import { IQueryModelService } from 'sql/platform/query/common/queryModel';
import { SelectBox } from 'sql/base/browser/ui/selectBox/selectBox';
import { attachEditableDropdownStyler, attachSelectBoxStyler } from 'sql/platform/theme/common/styler';
import { Dropdown } from 'sql/base/parts/editableDropdown/browser/dropdown';
import { IQueryManagementService } from 'sql/platform/query/common/queryManagement';
/**
* Action class that query-based Actions will extend. This base class automatically handles activating and
@@ -415,6 +416,61 @@ export class ListDatabasesAction extends QueryTaskbarAction {
}
}
/**
* Action class that toggles SQLCMD mode for the editor
*/
export class ToggleSqlCmdModeAction extends QueryTaskbarAction {
public static EnableSqlcmdClass = 'enablesqlcmd';
public static DisableSqlcmdClass = 'disablesqlcmd';
public static ID = 'ToggleSqlCmdModeAction';
private _enablesqlcmdLabel = nls.localize('enablesqlcmdLabel', "Enable SQLCMD Mode");
private _disablesqlcmdLabel = nls.localize('disablesqlcmdLabel', "Disable SQLCMD Mode");
constructor(
editor: QueryEditor,
private _isSqlCmdMode: boolean,
@IQueryManagementService protected readonly queryManagementService: IQueryManagementService,
@IConfigurationService protected readonly configurationService: IConfigurationService,
@IConnectionManagementService connectionManagementService: IConnectionManagementService
) {
super(connectionManagementService, editor, ToggleSqlCmdModeAction.ID, undefined);
}
public get isSqlCmdMode(): boolean {
return this._isSqlCmdMode;
}
public set isSqlCmdMode(value: boolean) {
this._isSqlCmdMode = value;
this.updateLabelAndIcon();
}
private updateLabelAndIcon(): void {
// show option to disable sql cmd mode if already enabled
this.label = this.isSqlCmdMode ? this._disablesqlcmdLabel : this._enablesqlcmdLabel;
this.isSqlCmdMode ? this.updateCssClass(ToggleSqlCmdModeAction.DisableSqlcmdClass) : this.updateCssClass(ToggleSqlCmdModeAction.EnableSqlcmdClass);
}
private setSqlCmdModeFalse() {
}
public run(): Promise<void> {
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<string, any>() };
queryoptions.options['isSqlCmdMode'] = toSqlCmdState;
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);
}
}
/*
* Action item that handles the dropdown (combobox) that lists the available databases.
* Based off StartDebugActionItem.

View File

@@ -85,6 +85,7 @@ export class QueryEditor extends BaseEditor {
private _estimatedQueryPlanAction: actions.EstimatedQueryPlanAction;
private _actualQueryPlanAction: actions.ActualQueryPlanAction;
private _listDatabasesActionItem: actions.ListDatabasesActionItem;
private _toggleSqlcmdMode: actions.ToggleSqlCmdModeAction;
constructor(
@ITelemetryService telemetryService: ITelemetryService,
@@ -181,6 +182,7 @@ export class QueryEditor extends BaseEditor {
this._listDatabasesAction = this.instantiationService.createInstance(actions.ListDatabasesAction, this);
this._estimatedQueryPlanAction = this.instantiationService.createInstance(actions.EstimatedQueryPlanAction, this);
this._actualQueryPlanAction = this.instantiationService.createInstance(actions.ActualQueryPlanAction, this);
this._toggleSqlcmdMode = this.instantiationService.createInstance(actions.ToggleSqlCmdModeAction, this, false);
this.setTaskbarContent();
@@ -205,6 +207,10 @@ export class QueryEditor extends BaseEditor {
}
}
if (stateChangeEvent.sqlCmdModeChanged) {
this._toggleSqlcmdMode.isSqlCmdMode = this.input.state.isSqlCmdMode;
}
if (stateChangeEvent.connectingChange) {
this._runQueryAction.enabled = !this.input.state.connecting;
this._estimatedQueryPlanAction.enabled = !this.input.state.connecting;
@@ -259,7 +265,8 @@ export class QueryEditor extends BaseEditor {
{ action: this._changeConnectionAction },
{ action: this._listDatabasesAction },
{ element: separator },
{ action: this._estimatedQueryPlanAction }
{ action: this._estimatedQueryPlanAction },
{ action: this._toggleSqlcmdMode }
];
// Remove the estimated query plan action if preview features are not enabled
@@ -309,7 +316,7 @@ export class QueryEditor extends BaseEditor {
dispose(this.inputDisposables);
this.inputDisposables = [];
this.inputDisposables.push(this.input.state.onChange(c => this.updateState(c)));
this.updateState({ connectingChange: true, connectedChange: true, executingChange: true, resultsVisibleChange: true });
this.updateState({ connectingChange: true, connectedChange: true, executingChange: true, resultsVisibleChange: true, sqlCmdModeChanged: true });
const editorViewState = this.loadTextEditorViewState(this.input.getResource());

View File

@@ -42,10 +42,12 @@ export interface IQueryEditorStateChange {
resultsVisibleChange?: boolean;
executingChange?: boolean;
connectingChange?: boolean;
sqlCmdModeChanged?: boolean;
}
export class QueryEditorState extends Disposable {
private _connected = false;
private _isSqlCmdMode = false;
private _resultsVisible = false;
private _executing = false;
private _connecting = false;
@@ -96,6 +98,17 @@ export class QueryEditorState extends Disposable {
public get executing(): boolean {
return this._executing;
}
public set isSqlCmdMode(val: boolean) {
if (val !== this._isSqlCmdMode) {
this._isSqlCmdMode = val;
this._onChange.fire({ sqlCmdModeChanged: true });
}
}
public get isSqlCmdMode(): boolean {
return this._isSqlCmdMode;
}
}
/**