Skip to content

Commit c15151b

Browse files
committed
Improved UX for cancelling in a view
Signed-off-by: worksofliam <[email protected]>
1 parent 00fc23d commit c15151b

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

src/connection/manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ export class SQLJobManager {
9494
return this.jobs;
9595
}
9696

97-
getJob(name: string): JobInfo | undefined {
98-
return this.jobs.find(info => info.name === name);
97+
getJob(nameOrId: string): JobInfo | undefined {
98+
return this.jobs.find(info => info.name === nameOrId || info.job.id === nameOrId);
9999
}
100100

101101
setSelection(selectedName: string): JobInfo|undefined {

src/views/results/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ export function initialise(context: vscode.ExtensionContext) {
5757
webviewOptions: { retainContextWhenHidden: true },
5858
}),
5959

60-
vscode.commands.registerCommand(`vscode-db2i.statement.cancel`, async () => {
61-
const selected = JobManager.getSelection();
60+
vscode.commands.registerCommand(`vscode-db2i.statement.cancel`, async (jobName?: string) => {
61+
const selected = typeof jobName === `string` ? JobManager.getJob(jobName) : JobManager.getSelection();
6262
if (selected) {
6363
updateStatusBar({canceling: true});
6464
const cancelled = await selected.job.requestCancel();

src/views/results/resultSetPanelProvider.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Query, QueryState } from "../../connection/query";
66
import { updateStatusBar } from "../jobManager/statusBar";
77
import Configuration from "../../configuration";
88
import * as html from "./html";
9+
import { JobStatus } from "../../connection/sqlJob";
910

1011
export class ResultSetPanelProvider implements WebviewViewProvider {
1112
_view: WebviewView | WebviewPanel;
@@ -16,14 +17,25 @@ export class ResultSetPanelProvider implements WebviewViewProvider {
1617
this.loadingState = false;
1718
}
1819

20+
endQuery() {
21+
if (this.currentQuery) {
22+
const hostJob = this.currentQuery.getHostJob();
23+
if (hostJob && hostJob.getStatus() === JobStatus.Busy) {
24+
// We are assuming the job is the same here.
25+
commands.executeCommand(`vscode-db2i.statement.cancel`, hostJob.id);
26+
}
27+
this.currentQuery.close().then(() => {
28+
this.currentQuery = undefined;
29+
});
30+
}
31+
}
32+
1933
resolveWebviewView(webviewView: WebviewView | WebviewPanel, context?: WebviewViewResolveContext, _token?: CancellationToken) {
2034
this._view = webviewView;
2135

2236
this._view.onDidDispose(() => {
2337
this._view = undefined;
24-
this.currentQuery.close().then(() => {
25-
this.currentQuery = undefined;
26-
});
38+
this.endQuery();
2739
});
2840

2941
webviewView.webview.options = {
@@ -35,10 +47,7 @@ export class ResultSetPanelProvider implements WebviewViewProvider {
3547
this._view.webview.onDidReceiveMessage(async (message) => {
3648
switch (message.command) {
3749
case `cancel`:
38-
commands.executeCommand(`vscode-db2i.statement.cancel`);
39-
if (this.currentQuery) {
40-
await this.currentQuery.close();
41-
}
50+
this.endQuery();
4251
break;
4352

4453
default:

0 commit comments

Comments
 (0)