Skip to content

Commit e23a3e1

Browse files
laurenastrid1Lauren Nathan
andauthored
Fix error edge case for clicking query plan links (#20364)
Co-authored-by: Lauren Nathan <[email protected]>
1 parent ae84b7a commit e23a3e1

File tree

5 files changed

+50
-10
lines changed

5 files changed

+50
-10
lines changed

src/constants/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ export const ipAddressRegex =
168168
/\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/;
169169
export const xml = "xml";
170170
export const json = "json";
171+
export const queryPlan = "Query Plan";
171172
export const queryPlanXmlStart = "<ShowPlanXML";
172173

173174
/**

src/controllers/mainController.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ import {
5353
DatabaseObject,
5454
} from "../services/databaseObjectSearchService";
5555
import { ExecutionPlanService } from "../services/executionPlanService";
56-
import { ExecutionPlanWebviewController } from "./executionPlanWebviewController";
5756
import { MssqlProtocolHandler } from "../mssqlProtocolHandler";
5857
import { getErrorMessage, getUriKey, isIConnectionInfo } from "../utils/utils";
5958
import { getStandardNPSQuestions, UserSurvey } from "../nps/userSurvey";
@@ -93,6 +92,7 @@ import {
9392
} from "../deployment/dockerUtils";
9493
import { ScriptOperation } from "../models/contracts/scripting/scriptingRequest";
9594
import { getCloudId } from "../azure/providerSettings";
95+
import { openExecutionPlanWebview } from "./sharedExecutionPlanUtils";
9696

9797
/**
9898
* The main controller class that initializes the extension
@@ -2884,18 +2884,14 @@ export default class MainController implements vscode.Disposable {
28842884

28852885
vscode.commands.executeCommand("workbench.action.closeActiveEditor");
28862886

2887-
const executionPlanController = new ExecutionPlanWebviewController(
2887+
openExecutionPlanWebview(
28882888
this.context,
28892889
this.vscodeWrapper,
28902890
this.executionPlanService,
28912891
this.sqlDocumentService,
28922892
planContents,
28932893
docName,
28942894
);
2895-
2896-
executionPlanController.revealToForeground();
2897-
2898-
sendActionEvent(TelemetryViews.ExecutionPlan, TelemetryActions.Open);
28992895
}
29002896
};
29012897
}

src/controllers/sharedExecutionPlanUtils.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,30 @@ import { TelemetryActions, TelemetryViews } from "../sharedInterfaces/telemetry"
1919
import { sendActionEvent, sendErrorEvent } from "../telemetry/telemetry";
2020
import { sqlPlanLanguageId } from "../constants/constants";
2121
import { executionPlanFileFilter } from "../constants/locConstants";
22+
import { ExecutionPlanWebviewController } from "./executionPlanWebviewController";
23+
import VscodeWrapper from "./vscodeWrapper";
2224

25+
export function openExecutionPlanWebview(
26+
context: vscode.ExtensionContext,
27+
vscodeWrapper: VscodeWrapper,
28+
executionPlanService: ExecutionPlanService,
29+
sqlDocumentService: SqlDocumentService,
30+
planContents: string,
31+
docName: string,
32+
) {
33+
const executionPlanController = new ExecutionPlanWebviewController(
34+
context,
35+
vscodeWrapper,
36+
executionPlanService,
37+
sqlDocumentService,
38+
planContents,
39+
docName,
40+
);
41+
42+
executionPlanController.revealToForeground();
43+
44+
sendActionEvent(TelemetryViews.ExecutionPlan, TelemetryActions.Open);
45+
}
2346
export async function saveExecutionPlan(
2447
state: QueryResultWebviewState | ExecutionPlanWebviewState,
2548
payload: ExecutionPlanReducers["saveExecutionPlan"],

src/queryResult/queryResultWebViewController.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class QueryResultWebviewController extends ReactWebviewViewController<
4545
constructor(
4646
context: vscode.ExtensionContext,
4747
vscodeWrapper: VscodeWrapper,
48-
private executionPlanService: ExecutionPlanService,
48+
private _executionPlanService: ExecutionPlanService,
4949
private _sqlOutputContentProvider: SqlOutputContentProvider,
5050
) {
5151
super(context, vscodeWrapper, "queryResult", "queryResult", {
@@ -392,8 +392,16 @@ export class QueryResultWebviewController extends ReactWebviewViewController<
392392
return this._sqlOutputContentProvider;
393393
}
394394

395-
public getExecutionPlanService(): ExecutionPlanService {
396-
return this.executionPlanService;
395+
public getContext(): vscode.ExtensionContext {
396+
return this._context;
397+
}
398+
399+
public getVsCodeWrapper(): VscodeWrapper {
400+
return this.vscodeWrapper;
401+
}
402+
403+
public get executionPlanService(): ExecutionPlanService {
404+
return this._executionPlanService;
397405
}
398406

399407
public set sqlDocumentService(service: SqlDocumentService) {

src/queryResult/utils.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as Constants from "../constants/constants";
88
import * as vscode from "vscode";
99
import { TelemetryViews, TelemetryActions } from "../sharedInterfaces/telemetry";
1010
import {
11+
openExecutionPlanWebview,
1112
saveExecutionPlan,
1213
showPlanXml,
1314
showQuery,
@@ -313,7 +314,18 @@ export function registerCommonRequestHandlers(
313314
payload.type === Constants.xml &&
314315
payload.content.startsWith(Constants.queryPlanXmlStart)
315316
) {
316-
state.tabStates.resultPaneTab = qr.QueryResultPaneTabs.ExecutionPlan;
317+
if (state.isExecutionPlan) {
318+
state.tabStates.resultPaneTab = qr.QueryResultPaneTabs.ExecutionPlan;
319+
return state;
320+
}
321+
openExecutionPlanWebview(
322+
webviewViewController.getContext(),
323+
webviewViewController.getVsCodeWrapper(),
324+
webviewViewController.executionPlanService,
325+
webviewViewController.sqlDocumentService,
326+
payload.content,
327+
Constants.queryPlan,
328+
);
317329
return state;
318330
}
319331

0 commit comments

Comments
 (0)