diff --git a/src/sql/parts/query/editor/queryEditor.ts b/src/sql/parts/query/editor/queryEditor.ts index 8db8df87eb..633dbddb06 100644 --- a/src/sql/parts/query/editor/queryEditor.ts +++ b/src/sql/parts/query/editor/queryEditor.ts @@ -41,7 +41,7 @@ import { Taskbar, ITaskbarContent } from 'sql/base/browser/ui/taskbar/taskbar'; import { RunQueryAction, CancelQueryAction, ListDatabasesAction, ListDatabasesActionItem, ConnectDatabaseAction, ToggleConnectDatabaseAction, EstimatedQueryPlanAction, - ActualQueryPlanAction + ActualQueryPlanAction, ParseSyntaxAction } from 'sql/parts/query/execution/queryActions'; import { IQueryModelService } from 'sql/parts/query/execution/queryModel'; import { IEditorDescriptorService } from 'sql/parts/query/editor/editorDescriptorService'; @@ -87,6 +87,7 @@ export class QueryEditor extends BaseEditor { private _listDatabasesAction: ListDatabasesAction; private _estimatedQueryPlanAction: EstimatedQueryPlanAction; private _actualQueryPlanAction: ActualQueryPlanAction; + private _parseSyntaxAction: ParseSyntaxAction; private _savedViewStates = new Map(); @@ -368,6 +369,22 @@ export class QueryEditor extends BaseEditor { return true; } + public getAllText(): string { + if (this._sqlEditor && this._sqlEditor.getControl()) { + let control = this._sqlEditor.getControl(); + let codeEditor: CodeEditor = control; + if (codeEditor) { + let value = codeEditor.getValue(); + if (value !== undefined && value.length > 0) { + return value; + } else { + return ''; + } + } + } + return undefined; + } + public getSelectionText(): string { if (this._sqlEditor && this._sqlEditor.getControl()) { let control = this._sqlEditor.getControl(); @@ -437,6 +454,7 @@ export class QueryEditor extends BaseEditor { this._listDatabasesAction = this._instantiationService.createInstance(ListDatabasesAction, this); this._estimatedQueryPlanAction = this._instantiationService.createInstance(EstimatedQueryPlanAction, this); this._actualQueryPlanAction = this._instantiationService.createInstance(ActualQueryPlanAction, this); + this._parseSyntaxAction = this._instantiationService.createInstance(ParseSyntaxAction, this); // Create HTML Elements for the taskbar let separator = Taskbar.createTaskbarSeparator(); @@ -451,6 +469,7 @@ export class QueryEditor extends BaseEditor { { action: this._listDatabasesAction }, { element: separator }, { action: this._estimatedQueryPlanAction }, + { action: this._parseSyntaxAction } ]; this._taskbar.setContent(content); } diff --git a/src/sql/parts/query/execution/queryActions.ts b/src/sql/parts/query/execution/queryActions.ts index f680764561..189647b815 100644 --- a/src/sql/parts/query/execution/queryActions.ts +++ b/src/sql/parts/query/execution/queryActions.ts @@ -25,6 +25,7 @@ import { QueryEditor } from 'sql/parts/query/editor/queryEditor'; import { IQueryModelService } from 'sql/parts/query/execution/queryModel'; import { INotificationService } from 'vs/platform/notification/common/notification'; import Severity from 'vs/base/common/severity'; +import { IQueryManagementService } from 'sql/parts/query/common/queryManagement'; /** * Action class that query-based Actions will extend. This base class automatically handles activating and @@ -417,6 +418,55 @@ export class ListDatabasesAction extends QueryTaskbarAction { } } +/** + * Action class that parses the query string in the current SQL text document. + */ +export class ParseSyntaxAction extends QueryTaskbarAction { + + public static EnabledClass = ''; + public static ID = 'parseQueryAction'; + + constructor( + editor: QueryEditor, + @IConnectionManagementService connectionManagementService: IConnectionManagementService, + @IQueryManagementService private _queryManagementService: IQueryManagementService, + @INotificationService private _notificationService: INotificationService, + ) { + super(connectionManagementService, editor, ParseSyntaxAction.ID, ParseSyntaxAction.EnabledClass); + this.enabled = true; + this.label = nls.localize('parseSyntaxLabel', 'Parse Query'); + } + + public run(): TPromise { + if (!this.editor.isSelectionEmpty()) { + if (this.isConnected(this.editor)) { + let text = this.editor.getSelectionText(); + if (text === '') { + text = this.editor.getAllText(); + } + this._queryManagementService.parseSyntax(this.editor.connectedUri, text).then(result => { + if (result && result.parseable) { + this._notificationService.notify({ + severity: Severity.Info, + message: nls.localize('queryActions.parseSyntaxSuccess', 'Commands completed successfully') + }); + } else if (result && result.errors.length > 0) { + let errorMessage = nls.localize('queryActions.parseSyntaxFailure', 'Command failed: '); + this._notificationService.error(`${errorMessage}${result.errors[0]}`); + + } + }); + } else { + this._notificationService.notify({ + severity: Severity.Error, + message: nls.localize('queryActions.notConnected', 'Please connect to a server') + }); + } + } + return TPromise.as(null); + } +} + /* * Action item that handles the dropdown (combobox) that lists the available databases. * Based off StartDebugActionItem. diff --git a/src/sql/parts/query/views/queryOutput.component.ts b/src/sql/parts/query/views/queryOutput.component.ts index c436f97016..6c3a4e2b03 100644 --- a/src/sql/parts/query/views/queryOutput.component.ts +++ b/src/sql/parts/query/views/queryOutput.component.ts @@ -17,7 +17,6 @@ import { IQueryComponentParams } from 'sql/services/bootstrap/bootstrapParams'; import { QueryComponent } from 'sql/parts/grid/views/query/query.component'; import { QueryPlanComponent } from 'sql/parts/queryPlan/queryPlan.component'; import { TopOperationsComponent } from 'sql/parts/queryPlan/topOperations.component'; -import { ChartViewerComponent } from 'sql/parts/grid/views/query/chartViewer.component'; import { toDisposableSubscription } from 'sql/parts/common/rxjsUtils'; import { PanelComponent, IPanelOptions } from 'sql/base/browser/ui/panel/panel.component'; diff --git a/src/sql/sqlops.d.ts b/src/sql/sqlops.d.ts index b9def8914d..5fcba5696a 100644 --- a/src/sql/sqlops.d.ts +++ b/src/sql/sqlops.d.ts @@ -777,7 +777,7 @@ declare module 'sqlops' { export interface SyntaxParseResult { parseable: boolean; - errorMessages: string[]; + errors: string[]; } // Query Batch Notification -----------------------------------------------------------------------