Skip to content

Commit 7da3740

Browse files
Merge pull request #3517 from github/robertbrignull/fix-token-alerts
Mark progress bars as cancellable where it appears we are respecting the token
2 parents 3508dc6 + 4e43a07 commit 7da3740

File tree

6 files changed

+74
-88
lines changed

6 files changed

+74
-88
lines changed

extensions/ql-vscode/src/common/vscode/progress.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type ProgressOptions = Optional<VSCodeProgressOptions, "location">;
4848
* denote some progress being achieved on this task.
4949
* @param token a cancellation token
5050
*/
51-
export type ProgressTask<R> = (
51+
type ProgressTask<R> = (
5252
progress: ProgressCallback,
5353
token: CancellationToken,
5454
) => Thenable<R>;

extensions/ql-vscode/src/databases/local-databases-ui.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,14 +645,13 @@ export class DatabaseUI extends DisposableObject {
645645

646646
private async handleClearCache(): Promise<void> {
647647
return withProgress(
648-
async (_progress, token) => {
648+
async () => {
649649
if (
650650
this.queryServer !== undefined &&
651651
this.databaseManager.currentDatabaseItem !== undefined
652652
) {
653653
await this.queryServer.clearCacheInDatabase(
654654
this.databaseManager.currentDatabaseItem,
655-
token,
656655
);
657656
}
658657
},
@@ -664,14 +663,13 @@ export class DatabaseUI extends DisposableObject {
664663

665664
private async handleTrimCache(): Promise<void> {
666665
return withProgress(
667-
async (_progress, token) => {
666+
async () => {
668667
if (
669668
this.queryServer !== undefined &&
670669
this.databaseManager.currentDatabaseItem !== undefined
671670
) {
672671
await this.queryServer.trimCacheInDatabase(
673672
this.databaseManager.currentDatabaseItem,
674-
token,
675673
);
676674
}
677675
},

extensions/ql-vscode/src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ function getCommands(
184184

185185
const restartQueryServer = async () =>
186186
withProgress(
187-
async (progress: ProgressCallback, token: CancellationToken) => {
187+
async (progress: ProgressCallback) => {
188188
// Restart all of the spawned servers: cli, query, and language.
189189
cliServer.restartCliServer();
190190
await Promise.all([
191-
queryRunner.restartQueryServer(progress, token),
191+
queryRunner.restartQueryServer(progress),
192192
async () => {
193193
if (languageClient.isRunning()) {
194194
await languageClient.restart();

extensions/ql-vscode/src/model-editor/model-editor-view.ts

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -814,58 +814,61 @@ export class ModelEditorView extends AbstractWebview<
814814
}
815815

816816
private async modelDependency(): Promise<void> {
817-
return withProgress(async (progress, token) => {
818-
const addedDatabase =
819-
await this.promptChooseNewOrExistingDatabase(progress);
820-
if (!addedDatabase || token.isCancellationRequested) {
821-
return;
822-
}
817+
return withProgress(
818+
async (progress, token) => {
819+
const addedDatabase =
820+
await this.promptChooseNewOrExistingDatabase(progress);
821+
if (!addedDatabase || token.isCancellationRequested) {
822+
return;
823+
}
823824

824-
const addedDbUri = addedDatabase.databaseUri.toString();
825-
if (this.modelingStore.isDbOpen(addedDbUri)) {
826-
this.modelingEvents.fireFocusModelEditorEvent(addedDbUri);
827-
return;
828-
}
825+
const addedDbUri = addedDatabase.databaseUri.toString();
826+
if (this.modelingStore.isDbOpen(addedDbUri)) {
827+
this.modelingEvents.fireFocusModelEditorEvent(addedDbUri);
828+
return;
829+
}
829830

830-
const modelFile = await pickExtensionPack(
831-
this.cliServer,
832-
addedDatabase,
833-
this.modelConfig,
834-
this.app.logger,
835-
progress,
836-
token,
837-
3,
838-
);
839-
if (!modelFile) {
840-
return;
841-
}
831+
const modelFile = await pickExtensionPack(
832+
this.cliServer,
833+
addedDatabase,
834+
this.modelConfig,
835+
this.app.logger,
836+
progress,
837+
token,
838+
3,
839+
);
840+
if (!modelFile) {
841+
return;
842+
}
842843

843-
// Check again just before opening the editor to ensure no model editor has been opened between
844-
// our first check and now.
845-
if (this.modelingStore.isDbOpen(addedDbUri)) {
846-
this.modelingEvents.fireFocusModelEditorEvent(addedDbUri);
847-
return;
848-
}
844+
// Check again just before opening the editor to ensure no model editor has been opened between
845+
// our first check and now.
846+
if (this.modelingStore.isDbOpen(addedDbUri)) {
847+
this.modelingEvents.fireFocusModelEditorEvent(addedDbUri);
848+
return;
849+
}
849850

850-
const view = new ModelEditorView(
851-
this.app,
852-
this.modelingStore,
853-
this.modelingEvents,
854-
this.modelConfig,
855-
this.databaseManager,
856-
this.databaseFetcher,
857-
this.variantAnalysisManager,
858-
this.cliServer,
859-
this.queryRunner,
860-
this.queryStorageDir,
861-
this.queryDir,
862-
addedDatabase,
863-
modelFile,
864-
this.language,
865-
Mode.Framework,
866-
);
867-
await view.openView();
868-
});
851+
const view = new ModelEditorView(
852+
this.app,
853+
this.modelingStore,
854+
this.modelingEvents,
855+
this.modelConfig,
856+
this.databaseManager,
857+
this.databaseFetcher,
858+
this.variantAnalysisManager,
859+
this.cliServer,
860+
this.queryRunner,
861+
this.queryStorageDir,
862+
this.queryDir,
863+
addedDatabase,
864+
modelFile,
865+
this.language,
866+
Mode.Framework,
867+
);
868+
await view.openView();
869+
},
870+
{ cancellable: true },
871+
);
869872
}
870873

871874
private async promptChooseNewOrExistingDatabase(

extensions/ql-vscode/src/query-server/query-runner.ts

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -91,26 +91,15 @@ export class QueryRunner {
9191
return this.qs.logger;
9292
}
9393

94-
async restartQueryServer(
95-
progress: ProgressCallback,
96-
token: CancellationToken,
97-
): Promise<void> {
98-
await this.qs.restartQueryServer(progress, token);
94+
async restartQueryServer(progress: ProgressCallback): Promise<void> {
95+
await this.qs.restartQueryServer(progress);
9996
}
10097

101-
onStart(
102-
callBack: (
103-
progress: ProgressCallback,
104-
token: CancellationToken,
105-
) => Promise<void>,
106-
) {
98+
onStart(callBack: (progress: ProgressCallback) => Promise<void>) {
10799
this.qs.onDidStartQueryServer(callBack);
108100
}
109101

110-
async clearCacheInDatabase(
111-
dbItem: DatabaseItem,
112-
token: CancellationToken,
113-
): Promise<void> {
102+
async clearCacheInDatabase(dbItem: DatabaseItem): Promise<void> {
114103
if (dbItem.contents === undefined) {
115104
throw new Error("Can't clear the cache in an invalid database.");
116105
}
@@ -120,13 +109,10 @@ export class QueryRunner {
120109
dryRun: false,
121110
db,
122111
};
123-
await this.qs.sendRequest(clearCache, params, token);
112+
await this.qs.sendRequest(clearCache, params);
124113
}
125114

126-
async trimCacheInDatabase(
127-
dbItem: DatabaseItem,
128-
token: CancellationToken,
129-
): Promise<void> {
115+
async trimCacheInDatabase(dbItem: DatabaseItem): Promise<void> {
130116
if (dbItem.contents === undefined) {
131117
throw new Error("Can't trim the cache in an invalid database.");
132118
}
@@ -135,7 +121,7 @@ export class QueryRunner {
135121
const params: TrimCacheParams = {
136122
db,
137123
};
138-
await this.qs.sendRequest(trimCache, params, token);
124+
await this.qs.sendRequest(trimCache, params);
139125
}
140126

141127
public async compileAndRunQueryAgainstDatabaseCore(

extensions/ql-vscode/src/query-server/query-server-client.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type { ProgressReporter } from "../common/logging/vscode";
1414
import { extLogger } from "../common/logging/vscode";
1515
import type { ProgressMessage, WithProgressId } from "./messages";
1616
import { progress } from "./messages";
17-
import type { ProgressCallback, ProgressTask } from "../common/vscode/progress";
17+
import type { ProgressCallback } from "../common/vscode/progress";
1818
import { withProgress } from "../common/vscode/progress";
1919
import { ServerProcess } from "./server-process";
2020
import type { App } from "../common/app";
@@ -51,12 +51,16 @@ export class QueryServerClient extends DisposableObject {
5151

5252
withProgressReporting: WithProgressReporting;
5353

54-
private readonly queryServerStartListeners = [] as Array<ProgressTask<void>>;
54+
private readonly queryServerStartListeners = [] as Array<
55+
(progress: ProgressCallback) => void
56+
>;
5557

5658
// Can't use standard vscode EventEmitter here since they do not cause the calling
5759
// function to fail if one of the event handlers fail. This is something that
5860
// we need here.
59-
readonly onDidStartQueryServer = (e: ProgressTask<void>) => {
61+
readonly onDidStartQueryServer = (
62+
e: (progress: ProgressCallback) => void,
63+
) => {
6064
this.queryServerStartListeners.push(e);
6165
};
6266

@@ -105,14 +109,11 @@ export class QueryServerClient extends DisposableObject {
105109
* This resets the unexpected termination count. As hopefully it is an indication that the user has fixed the
106110
* issue.
107111
*/
108-
async restartQueryServer(
109-
progress: ProgressCallback,
110-
token: CancellationToken,
111-
): Promise<void> {
112+
async restartQueryServer(progress: ProgressCallback): Promise<void> {
112113
// Reset the unexpected termination count when we restart the query server manually
113114
// or due to config change
114115
this.unexpectedTerminationCount = 0;
115-
await this.restartQueryServerInternal(progress, token);
116+
await this.restartQueryServerInternal(progress);
116117
}
117118

118119
/**
@@ -121,8 +122,7 @@ export class QueryServerClient extends DisposableObject {
121122
private restartQueryServerOnFailure() {
122123
if (this.unexpectedTerminationCount < MAX_UNEXPECTED_TERMINATIONS) {
123124
void withProgress(
124-
async (progress, token) =>
125-
this.restartQueryServerInternal(progress, token),
125+
async (progress) => this.restartQueryServerInternal(progress),
126126
{
127127
title: "Restarting CodeQL query server due to unexpected termination",
128128
},
@@ -144,15 +144,14 @@ export class QueryServerClient extends DisposableObject {
144144
*/
145145
private async restartQueryServerInternal(
146146
progress: ProgressCallback,
147-
token: CancellationToken,
148147
): Promise<void> {
149148
this.stopQueryServer();
150149
await this.startQueryServer();
151150

152151
// Ensure we await all responses from event handlers so that
153152
// errors can be properly reported to the user.
154153
await Promise.all(
155-
this.queryServerStartListeners.map((handler) => handler(progress, token)),
154+
this.queryServerStartListeners.map((handler) => handler(progress)),
156155
);
157156
}
158157

0 commit comments

Comments
 (0)