update parse query action (#22577)

* update parse query action

* revert export notebook change

* comment
This commit is contained in:
Alan Ren
2023-03-31 18:24:47 -07:00
committed by GitHub
parent 0f21ecd531
commit 2a14562ec7
5 changed files with 50 additions and 24 deletions

View File

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

View File

@@ -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<void> {
public override async run(): Promise<void> {
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);
}
/**

View File

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

View File

@@ -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<void> {
this._commandService.executeCommand(ParseSyntaxCommandId);
}
}

View File

@@ -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(