From 2a14562ec71b108cef3f0840f62b58a66c7115c2 Mon Sep 17 00:00:00 2001 From: Alan Ren Date: Fri, 31 Mar 2023 18:24:47 -0700 Subject: [PATCH] update parse query action (#22577) * update parse query action * revert export notebook change * comment --- .../base/browser/ui/taskbar/media/taskbar.css | 12 +++++++ .../query/browser/keyboardQueryActions.ts | 32 ++++++++----------- .../query/browser/query.contribution.ts | 7 ++-- .../contrib/query/browser/queryActions.ts | 18 +++++++++-- .../contrib/query/browser/queryEditor.ts | 5 +++ 5 files changed, 50 insertions(+), 24 deletions(-) diff --git a/src/sql/base/browser/ui/taskbar/media/taskbar.css b/src/sql/base/browser/ui/taskbar/media/taskbar.css index 4f335168fe..3bc1c12928 100644 --- a/src/sql/base/browser/ui/taskbar/media/taskbar.css +++ b/src/sql/base/browser/ui/taskbar/media/taskbar.css @@ -143,3 +143,15 @@ width: 100%; margin-left: 0; } + +.carbon-taskbar .monaco-action-bar .action-item .codicon.action-label[class*='codicon-'] { + font-size: 11px; + padding-left: 0px; + font-family: inherit; +} + +.carbon-taskbar .monaco-action-bar .action-item .codicon.action-label[class*='codicon-']:before { + font-size: 16px; + font-family: 'codicon'; + padding-right: 2px; +} diff --git a/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts b/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts index d8fca3969f..915dc4fdbb 100644 --- a/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts +++ b/src/sql/workbench/contrib/query/browser/keyboardQueryActions.ts @@ -521,8 +521,6 @@ export class RunQueryShortcutAction extends Action { * Action class that parses the query string in the current SQL text document. */ export class ParseSyntaxAction extends Action { - - public static ID = 'parseQueryAction'; public static LABEL = nls.localize('parseSyntaxLabel', "Parse Query"); constructor( @@ -537,7 +535,7 @@ export class ParseSyntaxAction extends Action { this.enabled = true; } - public override run(): Promise { + public override async run(): Promise { const editor = this.editorService.activeEditorPane; if (editor instanceof QueryEditor) { if (!editor.isSelectionEmpty()) { @@ -546,29 +544,25 @@ export class ParseSyntaxAction extends Action { if (text === '') { text = editor.getAllText(); } - this.queryManagementService.parseSyntax(editor.input.uri, 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]}`); - - } - }); + const result = await this.queryManagementService.parseSyntax(editor.input.uri, text); + if (result && result.parseable) { + this.notificationService.notify({ + severity: Severity.Info, + message: nls.localize('queryActions.parseSyntaxSuccess', "Successfully parsed the query.") + }); + } else if (result && result.errors.length > 0) { + this.notificationService.error( + nls.localize('queryActions.parseSyntaxFailure', "Failed to parse the query: {0}", + result.errors.map((err, idx) => `${idx + 1}. ${err} `).join(' '))); + } } else { this.notificationService.notify({ severity: Severity.Error, - message: nls.localize('queryActions.notConnected', "Please connect to a server") + message: nls.localize('queryActions.notConnected', "Please connect to a server before running this action.") }); } } - } - - return Promise.resolve(null); } /** diff --git a/src/sql/workbench/contrib/query/browser/query.contribution.ts b/src/sql/workbench/contrib/query/browser/query.contribution.ts index a41d21aeef..4686252eeb 100644 --- a/src/sql/workbench/contrib/query/browser/query.contribution.ts +++ b/src/sql/workbench/contrib/query/browser/query.contribution.ts @@ -34,7 +34,7 @@ import { FileQueryEditorInput } from 'sql/workbench/contrib/query/browser/fileQu import { FileQueryEditorSerializer, QueryEditorLanguageAssociation, UntitledQueryEditorSerializer } from 'sql/workbench/contrib/query/browser/queryEditorFactory'; import { UntitledQueryEditorInput } from 'sql/base/query/browser/untitledQueryEditorInput'; import { ILanguageAssociationRegistry, Extensions as LanguageAssociationExtensions } from 'sql/workbench/services/languageAssociation/common/languageAssociation'; -import { NewQueryTask, OE_NEW_QUERY_ACTION_ID, DE_NEW_QUERY_COMMAND_ID, CATEGORIES } from 'sql/workbench/contrib/query/browser/queryActions'; +import { NewQueryTask, OE_NEW_QUERY_ACTION_ID, DE_NEW_QUERY_COMMAND_ID, CATEGORIES, ParseSyntaxCommandId } from 'sql/workbench/contrib/query/browser/queryActions'; import { TreeNodeContextKey } from 'sql/workbench/services/objectExplorer/common/treeNodeContextKey'; import { MssqlNodeContext } from 'sql/workbench/services/objectExplorer/browser/mssqlNodeContext'; import { CommandsRegistry, ICommandService } from 'vs/platform/commands/common/commands'; @@ -199,8 +199,9 @@ actionRegistry.registerWorkbenchAction( actionRegistry.registerWorkbenchAction( SyncActionDescriptor.create( ParseSyntaxAction, - ParseSyntaxAction.ID, - ParseSyntaxAction.LABEL + ParseSyntaxCommandId, + ParseSyntaxAction.LABEL, + { primary: KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KeyP } ), ParseSyntaxAction.LABEL ); diff --git a/src/sql/workbench/contrib/query/browser/queryActions.ts b/src/sql/workbench/contrib/query/browser/queryActions.ts index b0c8bf9917..6bd0b1cf28 100644 --- a/src/sql/workbench/contrib/query/browser/queryActions.ts +++ b/src/sql/workbench/contrib/query/browser/queryActions.ts @@ -48,6 +48,7 @@ import { IActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar'; import { gen3Version, sqlDataWarehouse } from 'sql/platform/connection/common/constants'; import { Dropdown } from 'sql/base/browser/ui/editableDropdown/browser/dropdown'; import { IAdsTelemetryService } from 'sql/platform/telemetry/common/telemetry'; +import { Codicon } from 'vs/base/common/codicons'; /** * Action class that query-based Actions will extend. This base class automatically handles activating and @@ -916,8 +917,7 @@ export class ExportAsNotebookAction extends QueryTaskbarAction { @IConnectionManagementService connectionManagementService: IConnectionManagementService, @ICommandService private _commandService: ICommandService ) { - super(connectionManagementService, editor, ConnectDatabaseAction.ID, ExportAsNotebookAction.IconClass); - + super(connectionManagementService, editor, ExportAsNotebookAction.ID, ExportAsNotebookAction.IconClass); this.label = nls.localize('queryEditor.exportSqlAsNotebook', "Export as Notebook"); } @@ -929,3 +929,17 @@ export class ExportAsNotebookAction extends QueryTaskbarAction { export const CATEGORIES = { ExecutionPlan: { value: nls.localize('ExecutionPlan', 'Execution Plan'), original: 'Execution Plan' } }; + +// A wrapper for the ParseSyntaxAction. +// We are not able to reference the ParseSyntaxAction directly in QueryEditor.ts because there is a circular dependency issue. +// The command id is also defined here to avoid duplication. +export const ParseSyntaxCommandId = 'parseQueryAction'; +export class ParseSyntaxTaskbarAction extends Action { + constructor(@ICommandService private _commandService: ICommandService) { + super(ParseSyntaxCommandId, nls.localize('queryEditor.parse', "Parse"), Codicon.check.classNames); + } + + public override async run(): Promise { + this._commandService.executeCommand(ParseSyntaxCommandId); + } +} diff --git a/src/sql/workbench/contrib/query/browser/queryEditor.ts b/src/sql/workbench/contrib/query/browser/queryEditor.ts index f2fdb6bf04..6659c1ca15 100644 --- a/src/sql/workbench/contrib/query/browser/queryEditor.ts +++ b/src/sql/workbench/contrib/query/browser/queryEditor.ts @@ -100,6 +100,7 @@ export class QueryEditor extends EditorPane { private _toggleSqlcmdMode: actions.ToggleSqlCmdModeAction; private _toggleActualExecutionPlanMode: actions.ToggleActualExecutionPlanModeAction; private _exportAsNotebookAction: actions.ExportAsNotebookAction; + private _parseQueryAction: actions.ParseSyntaxTaskbarAction; constructor( @ITelemetryService telemetryService: ITelemetryService, @@ -211,6 +212,7 @@ export class QueryEditor extends EditorPane { this._toggleSqlcmdMode = this.instantiationService.createInstance(actions.ToggleSqlCmdModeAction, this, false); this._toggleActualExecutionPlanMode = this.instantiationService.createInstance(actions.ToggleActualExecutionPlanModeAction, this, false); this._exportAsNotebookAction = this.instantiationService.createInstance(actions.ExportAsNotebookAction, this); + this._parseQueryAction = this.instantiationService.createInstance(actions.ParseSyntaxTaskbarAction); this.setTaskbarContent(); this._register(this.configurationService.onDidChangeConfiguration(e => { if (e.affectsConfiguration(CONFIG_WORKBENCH_ENABLEPREVIEWFEATURES)) { @@ -269,6 +271,8 @@ export class QueryEditor extends EditorPane { this.removeResultsEditor(); } } + + this._parseQueryAction.enabled = this.input.state.connected && !this.input.state.executing; } /** @@ -332,6 +336,7 @@ export class QueryEditor extends EditorPane { { element: Taskbar.createTaskbarSeparator() }, { action: this._estimatedQueryPlanAction }, { action: this._toggleActualExecutionPlanMode }, + { action: this._parseQueryAction } ); if (previewFeaturesEnabled) { content.push(