Skip to content

Commit d9ac874

Browse files
Merge pull request #3466 from github/robertbrignull/remove_withInheritedProgress
Delete withInheritedProgress and ProgressContext
2 parents 06f9f2c + 0454130 commit d9ac874

File tree

5 files changed

+42
-92
lines changed

5 files changed

+42
-92
lines changed

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

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -85,29 +85,6 @@ export function withProgress<R>(
8585
);
8686
}
8787

88-
export interface ProgressContext {
89-
progress: ProgressCallback;
90-
token: CancellationToken;
91-
}
92-
93-
/**
94-
* Like `withProgress()`, except that the caller is not required to provide a progress context. If
95-
* the caller does provide one, any long-running operations performed by `task` will use the
96-
* supplied progress context. Otherwise, this function wraps `task` in a new progress context with
97-
* the supplied options.
98-
*/
99-
export function withInheritedProgress<R>(
100-
parent: ProgressContext | undefined,
101-
task: ProgressTask<R>,
102-
options: ProgressOptions,
103-
): Thenable<R> {
104-
if (parent !== undefined) {
105-
return task(parent.progress, parent.token);
106-
} else {
107-
return withProgress(task, options);
108-
}
109-
}
110-
11188
/**
11289
* Displays a progress monitor that indicates how much progess has been made
11390
* reading from a stream.

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

Lines changed: 33 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
ThemeIcon,
1717
ThemeColor,
1818
workspace,
19-
ProgressLocation,
2019
} from "vscode";
2120
import { pathExists, stat, readdir, remove } from "fs-extra";
2221

@@ -25,13 +24,9 @@ import type {
2524
DatabaseItem,
2625
DatabaseManager,
2726
} from "./local-databases";
28-
import type {
29-
ProgressCallback,
30-
ProgressContext,
31-
} from "../common/vscode/progress";
27+
import type { ProgressCallback } from "../common/vscode/progress";
3228
import {
3329
UserCancellationException,
34-
withInheritedProgress,
3530
withProgress,
3631
} from "../common/vscode/progress";
3732
import {
@@ -332,10 +327,9 @@ export class DatabaseUI extends DisposableObject {
332327

333328
private async chooseDatabaseFolder(
334329
progress: ProgressCallback,
335-
token: CancellationToken,
336330
): Promise<void> {
337331
try {
338-
await this.chooseAndSetDatabase(true, { progress, token });
332+
await this.chooseAndSetDatabase(true, progress);
339333
} catch (e) {
340334
void showAndLogExceptionWithTelemetry(
341335
this.app.logger,
@@ -349,8 +343,8 @@ export class DatabaseUI extends DisposableObject {
349343

350344
private async handleChooseDatabaseFolder(): Promise<void> {
351345
return withProgress(
352-
async (progress, token) => {
353-
await this.chooseDatabaseFolder(progress, token);
346+
async (progress) => {
347+
await this.chooseDatabaseFolder(progress);
354348
},
355349
{
356350
title: "Adding database from folder",
@@ -360,8 +354,8 @@ export class DatabaseUI extends DisposableObject {
360354

361355
private async handleChooseDatabaseFolderFromPalette(): Promise<void> {
362356
return withProgress(
363-
async (progress, token) => {
364-
await this.chooseDatabaseFolder(progress, token);
357+
async (progress) => {
358+
await this.chooseDatabaseFolder(progress);
365359
},
366360
{
367361
title: "Choose a Database from a Folder",
@@ -502,10 +496,9 @@ export class DatabaseUI extends DisposableObject {
502496

503497
private async chooseDatabaseArchive(
504498
progress: ProgressCallback,
505-
token: CancellationToken,
506499
): Promise<void> {
507500
try {
508-
await this.chooseAndSetDatabase(false, { progress, token });
501+
await this.chooseAndSetDatabase(false, progress);
509502
} catch (e: unknown) {
510503
void showAndLogExceptionWithTelemetry(
511504
this.app.logger,
@@ -519,8 +512,8 @@ export class DatabaseUI extends DisposableObject {
519512

520513
private async handleChooseDatabaseArchive(): Promise<void> {
521514
return withProgress(
522-
async (progress, token) => {
523-
await this.chooseDatabaseArchive(progress, token);
515+
async (progress) => {
516+
await this.chooseDatabaseArchive(progress);
524517
},
525518
{
526519
title: "Adding database from archive",
@@ -530,8 +523,8 @@ export class DatabaseUI extends DisposableObject {
530523

531524
private async handleChooseDatabaseArchiveFromPalette(): Promise<void> {
532525
return withProgress(
533-
async (progress, token) => {
534-
await this.chooseDatabaseArchive(progress, token);
526+
async (progress) => {
527+
await this.chooseDatabaseArchive(progress);
535528
},
536529
{
537530
title: "Choose a Database from an Archive",
@@ -851,9 +844,8 @@ export class DatabaseUI extends DisposableObject {
851844
*/
852845
public async getDatabaseItem(
853846
progress: ProgressCallback,
854-
token: CancellationToken,
855847
): Promise<DatabaseItem | undefined> {
856-
return await this.getDatabaseItemInternal({ progress, token });
848+
return await this.getDatabaseItemInternal(progress);
857849
}
858850

859851
/**
@@ -866,10 +858,10 @@ export class DatabaseUI extends DisposableObject {
866858
* notification if it tries to perform any long-running operations.
867859
*/
868860
private async getDatabaseItemInternal(
869-
progressContext: ProgressContext | undefined,
861+
progress: ProgressCallback | undefined,
870862
): Promise<DatabaseItem | undefined> {
871863
if (this.databaseManager.currentDatabaseItem === undefined) {
872-
progressContext?.progress({
864+
progress?.({
873865
maxStep: 2,
874866
step: 1,
875867
message: "Choosing database",
@@ -996,41 +988,31 @@ export class DatabaseUI extends DisposableObject {
996988
*/
997989
private async chooseAndSetDatabase(
998990
byFolder: boolean,
999-
progress: ProgressContext | undefined,
991+
progress: ProgressCallback,
1000992
): Promise<DatabaseItem | undefined> {
1001993
const uri = await chooseDatabaseDir(byFolder);
1002994
if (!uri) {
1003995
return undefined;
1004996
}
1005997

1006-
return await withInheritedProgress(
1007-
progress,
1008-
async (progress) => {
1009-
if (byFolder) {
1010-
const fixedUri = await this.fixDbUri(uri);
1011-
// we are selecting a database folder
1012-
return await this.databaseManager.openDatabase(fixedUri, {
1013-
type: "folder",
1014-
});
1015-
} else {
1016-
// we are selecting a database archive. Must unzip into a workspace-controlled area
1017-
// before importing.
1018-
return await importLocalDatabase(
1019-
this.app.commands,
1020-
uri.toString(true),
1021-
this.databaseManager,
1022-
this.storagePath,
1023-
progress,
1024-
this.queryServer.cliServer,
1025-
);
1026-
}
1027-
},
1028-
{
1029-
location: ProgressLocation.Notification,
1030-
cancellable: true,
1031-
title: "Opening database",
1032-
},
1033-
);
998+
if (byFolder) {
999+
const fixedUri = await this.fixDbUri(uri);
1000+
// we are selecting a database folder
1001+
return await this.databaseManager.openDatabase(fixedUri, {
1002+
type: "folder",
1003+
});
1004+
} else {
1005+
// we are selecting a database archive. Must unzip into a workspace-controlled area
1006+
// before importing.
1007+
return await importLocalDatabase(
1008+
this.app.commands,
1009+
uri.toString(true),
1010+
this.databaseManager,
1011+
this.storagePath,
1012+
progress,
1013+
this.queryServer.cliServer,
1014+
);
1015+
}
10341016
}
10351017

10361018
/**

extensions/ql-vscode/src/local-queries/local-queries.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,8 @@ export class LocalQueries extends DisposableObject {
290290

291291
private async quickQuery(): Promise<void> {
292292
await withProgress(
293-
async (progress, token) =>
294-
displayQuickQuery(
295-
this.app,
296-
this.cliServer,
297-
this.databaseUI,
298-
progress,
299-
token,
300-
),
293+
async (progress) =>
294+
displayQuickQuery(this.app, this.cliServer, this.databaseUI, progress),
301295
{
302296
title: "Run Quick Query",
303297
},
@@ -445,7 +439,7 @@ export class LocalQueries extends DisposableObject {
445439

446440
// If no databaseItem is specified, use the database currently selected in the Databases UI
447441
databaseItem =
448-
databaseItem ?? (await this.databaseUI.getDatabaseItem(progress, token));
442+
databaseItem ?? (await this.databaseUI.getDatabaseItem(progress));
449443
if (databaseItem === undefined) {
450444
throw new Error("Can't run query without a selected database");
451445
}

extensions/ql-vscode/src/local-queries/quick-query.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { ensureDir, writeFile, pathExists, readFile } from "fs-extra";
22
import { dump, load } from "js-yaml";
33
import { basename, join } from "path";
4-
import type { CancellationToken } from "vscode";
54
import { window as Window, workspace, Uri } from "vscode";
65
import { LSPErrorCodes, ResponseError } from "vscode-languageclient";
76
import type { CodeQLCliServer } from "../codeql-cli/cli";
@@ -56,7 +55,6 @@ export async function displayQuickQuery(
5655
cliServer: CodeQLCliServer,
5756
databaseUI: DatabaseUI,
5857
progress: ProgressCallback,
59-
token: CancellationToken,
6058
) {
6159
try {
6260
// If there is already a quick query open, don't clobber it, just
@@ -111,7 +109,7 @@ export async function displayQuickQuery(
111109
}
112110

113111
// We're going to infer which qlpack to use from the current database
114-
const dbItem = await databaseUI.getDatabaseItem(progress, token);
112+
const dbItem = await databaseUI.getDatabaseItem(progress);
115113
if (dbItem === undefined) {
116114
throw new Error("Can't start quick query without a selected database");
117115
}

extensions/ql-vscode/test/vscode-tests/no-workspace/databases/local-databases-ui.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
createFileSync,
88
pathExistsSync,
99
} from "fs-extra";
10-
import { CancellationTokenSource, Uri, window } from "vscode";
10+
import { Uri, window } from "vscode";
1111

1212
import type {
1313
DatabaseImportQuickPickItems,
@@ -127,7 +127,6 @@ describe("local-databases-ui", () => {
127127

128128
describe("getDatabaseItem", () => {
129129
const progress = jest.fn();
130-
const token = new CancellationTokenSource().token;
131130
describe("when there is a current database", () => {
132131
const databaseUI = new DatabaseUI(
133132
app,
@@ -153,7 +152,7 @@ describe("local-databases-ui", () => {
153152
);
154153

155154
it("should return current database", async () => {
156-
const databaseItem = await databaseUI.getDatabaseItem(progress, token);
155+
const databaseItem = await databaseUI.getDatabaseItem(progress);
157156

158157
expect(databaseItem).toEqual({ databaseUri: Uri.file(db1) });
159158
});
@@ -211,7 +210,7 @@ describe("local-databases-ui", () => {
211210
"setCurrentDatabaseItem",
212211
);
213212

214-
await databaseUI.getDatabaseItem(progress, token);
213+
await databaseUI.getDatabaseItem(progress);
215214

216215
expect(showQuickPickSpy).toHaveBeenCalledTimes(2);
217216
expect(setCurrentDatabaseItemSpy).toHaveBeenCalledWith({
@@ -241,7 +240,7 @@ describe("local-databases-ui", () => {
241240
.spyOn(databaseUI as any, "handleChooseDatabaseGithub")
242241
.mockResolvedValue(undefined);
243242

244-
await databaseUI.getDatabaseItem(progress, token);
243+
await databaseUI.getDatabaseItem(progress);
245244

246245
expect(showQuickPickSpy).toHaveBeenCalledTimes(2);
247246
expect(handleChooseDatabaseGithubSpy).toHaveBeenCalledTimes(1);
@@ -264,7 +263,7 @@ describe("local-databases-ui", () => {
264263
.spyOn(databaseUI as any, "handleChooseDatabaseGithub")
265264
.mockResolvedValue(undefined);
266265

267-
await databaseUI.getDatabaseItem(progress, token);
266+
await databaseUI.getDatabaseItem(progress);
268267

269268
expect(showQuickPickSpy).toHaveBeenCalledTimes(1);
270269
expect(handleChooseDatabaseGithubSpy).toHaveBeenCalledTimes(1);

0 commit comments

Comments
 (0)