-
Notifications
You must be signed in to change notification settings - Fork 456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Query Plan to results pane #18124
base: main
Are you sure you want to change the base?
Changes from all commits
a1299ec
c1769c3
71e41ff
c49f6c8
a9acfee
0b0b740
106d109
f47ec3c
fcb0ccc
d3ab690
35f60fb
1a73a7f
330cebe
e2e059e
c7ebd90
ec7d41a
ef5246d
68b8ae0
828fb96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ import * as ep from "../reactviews/pages/ExecutionPlan/executionPlanInterfaces"; | |
import { homedir } from "os"; | ||
import { exists } from "../utils/utils"; | ||
import UntitledSqlDocumentService from "../controllers/untitledSqlDocumentService"; | ||
import * as path from "path"; | ||
import { ApiStatus } from "../sharedInterfaces/webview"; | ||
|
||
export class ExecutionPlanWebviewController extends ReactWebviewPanelController< | ||
|
@@ -30,16 +29,18 @@ export class ExecutionPlanWebviewController extends ReactWebviewPanelController< | |
`${xmlPlanFileName}`, // Sets the webview title | ||
"executionPlan", | ||
{ | ||
sqlPlanContent: executionPlanContents, | ||
theme: | ||
vscode.window.activeColorTheme.kind === | ||
vscode.ColorThemeKind.Dark | ||
? "dark" | ||
: "light", | ||
loadState: ApiStatus.Loading, | ||
executionPlan: undefined, | ||
executionPlanGraphs: [], | ||
totalCost: 0, | ||
executionPlanState: { | ||
sqlPlanContent: executionPlanContents, | ||
theme: | ||
vscode.window.activeColorTheme.kind === | ||
vscode.ColorThemeKind.Dark | ||
? "dark" | ||
: "light", | ||
loadState: ApiStatus.Loading, | ||
executionPlan: undefined, | ||
executionPlanGraphs: [], | ||
totalCost: 0, | ||
}, | ||
}, | ||
vscode.ViewColumn.Active, | ||
{ | ||
|
@@ -59,7 +60,7 @@ export class ExecutionPlanWebviewController extends ReactWebviewPanelController< | |
} | ||
|
||
private async initialize() { | ||
this.state.loadState = ApiStatus.Loading; | ||
this.state.executionPlanState.loadState = ApiStatus.Loading; | ||
this.updateState(); | ||
await this.createExecutionPlanGraphs(); | ||
this.registerRpcHandlers(); | ||
|
@@ -70,17 +71,21 @@ export class ExecutionPlanWebviewController extends ReactWebviewPanelController< | |
await this.createExecutionPlanGraphs(); | ||
return { | ||
...state, | ||
executionPlan: this.state.executionPlan, | ||
executionPlanGraphs: this.state.executionPlanGraphs, | ||
executionPlanState: { | ||
...state.executionPlanState, | ||
sqlPlanContent: payload.sqlPlanContent, | ||
executionPlan: this.state.executionPlanState.executionPlan, | ||
executionPlanGraphs: | ||
this.state.executionPlanState.executionPlanGraphs, | ||
}, | ||
}; | ||
}); | ||
this.registerReducer("saveExecutionPlan", async (state, payload) => { | ||
let folder = vscode.Uri.file(homedir()); | ||
if (await exists("Documents", folder)) { | ||
folder = vscode.Uri.file(path.join(folder.path, "Documents")); | ||
} | ||
|
||
let filename: vscode.Uri; | ||
|
||
// make the default filename of the plan to be saved- | ||
// start ad plan.sqlplan, then plan1.sqlplan, ... | ||
let counter = 1; | ||
if (await exists(`plan.sqlplan`, folder)) { | ||
while (await exists(`plan${counter}.sqlplan`, folder)) { | ||
|
@@ -104,7 +109,7 @@ export class ExecutionPlanWebviewController extends ReactWebviewPanelController< | |
|
||
if (saveUri) { | ||
// Write the content to the new file | ||
await vscode.workspace.fs.writeFile( | ||
vscode.workspace.fs.writeFile( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if |
||
saveUri, | ||
Buffer.from(payload.sqlPlanContent), | ||
); | ||
|
@@ -118,49 +123,58 @@ export class ExecutionPlanWebviewController extends ReactWebviewPanelController< | |
language: "xml", | ||
}); | ||
|
||
await vscode.window.showTextDocument(planXmlDoc); | ||
vscode.window.showTextDocument(planXmlDoc); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. void keyword |
||
|
||
return state; | ||
}); | ||
this.registerReducer("showQuery", async (state, payload) => { | ||
await this.untitledSqlDocumentService.newQuery(payload.query); | ||
this.untitledSqlDocumentService.newQuery(payload.query); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. void keyword |
||
|
||
return state; | ||
}); | ||
this.registerReducer("updateTotalCost", async (state, payload) => { | ||
this.state.totalCost += payload.totalCost; | ||
this.state.executionPlanState.totalCost += payload.addedCost; | ||
|
||
return { | ||
...state, | ||
totalCost: this.state.totalCost, | ||
executionPlanState: { | ||
...state.executionPlanState, | ||
totalCost: this.state.executionPlanState.totalCost, | ||
}, | ||
}; | ||
}); | ||
} | ||
|
||
private async createExecutionPlanGraphs() { | ||
if (!this.state.executionPlan) { | ||
if (!this.state.executionPlanState.executionPlan) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: Why not make this function cleaner and just create a new variable and add all the properties and the end
This will prevent you from repeating |
||
const planFile: ep.ExecutionPlanGraphInfo = { | ||
graphFileContent: this.executionPlanContents, | ||
graphFileType: ".sqlplan", | ||
}; | ||
try { | ||
this.state.executionPlan = | ||
this.state.executionPlanState.executionPlan = | ||
await this.executionPlanService.getExecutionPlan(planFile); | ||
this.state.executionPlanGraphs = | ||
this.state.executionPlan.graphs; | ||
this.state.loadState = ApiStatus.Loaded; | ||
this.state.totalCost = this.calculateTotalCost(); | ||
this.state.executionPlanState.executionPlanGraphs = | ||
this.state.executionPlanState.executionPlan.graphs; | ||
this.state.executionPlanState.loadState = ApiStatus.Loaded; | ||
this.state.executionPlanState.totalCost = | ||
this.calculateTotalCost(); | ||
} catch (e) { | ||
this.state.loadState = ApiStatus.Error; | ||
this.state.errorMessage = e.toString(); | ||
this.state.executionPlanState.loadState = ApiStatus.Error; | ||
this.state.executionPlanState.errorMessage = e.toString(); | ||
} | ||
this.updateState(); | ||
} | ||
this.updateState(); | ||
} | ||
|
||
private calculateTotalCost(): number { | ||
if (!this.state.executionPlanState.executionPlanGraphs) { | ||
this.state.executionPlanState.loadState = ApiStatus.Error; | ||
return 0; | ||
} | ||
|
||
let sum = 0; | ||
for (const graph of this.state.executionPlanGraphs!) { | ||
for (const graph of this.state.executionPlanState.executionPlanGraphs) { | ||
sum += graph.root.cost + graph.root.subTreeCost; | ||
} | ||
return sum; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the theme variable in vscodeWebviewContextProvider. This implementation already doesn't support high contrast theme.