Feature: Parse Query Syntax (#1997)

* feature/parseSyntax

* added error when no connection

* removed elapsed time logic

* code review comments

* changed error message to match SSMS
This commit is contained in:
Aditya Bist
2018-07-25 16:11:58 -07:00
committed by GitHub
parent 7cda45c904
commit 335b9f445f
4 changed files with 71 additions and 3 deletions

View File

@@ -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<IEditorInput, IEditorViewState>();
@@ -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 = <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);
}

View File

@@ -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<void> {
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.

View File

@@ -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';

2
src/sql/sqlops.d.ts vendored
View File

@@ -777,7 +777,7 @@ declare module 'sqlops' {
export interface SyntaxParseResult {
parseable: boolean;
errorMessages: string[];
errors: string[];
}
// Query Batch Notification -----------------------------------------------------------------------