Delete ProgressContext

This commit is contained in:
Robert
2024-03-13 17:45:06 +00:00
parent bf58e311dd
commit 16b8f848b5
5 changed files with 13 additions and 31 deletions

View File

@@ -85,11 +85,6 @@ export function withProgress<R>(
);
}
export interface ProgressContext {
progress: ProgressCallback;
token: CancellationToken;
}
/**
* Displays a progress monitor that indicates how much progess has been made
* reading from a stream.

View File

@@ -24,10 +24,7 @@ import type {
DatabaseItem,
DatabaseManager,
} from "./local-databases";
import type {
ProgressCallback,
ProgressContext,
} from "../common/vscode/progress";
import type { ProgressCallback } from "../common/vscode/progress";
import {
UserCancellationException,
withProgress,
@@ -791,9 +788,8 @@ export class DatabaseUI extends DisposableObject {
*/
public async getDatabaseItem(
progress: ProgressCallback,
token: CancellationToken,
): Promise<DatabaseItem | undefined> {
return await this.getDatabaseItemInternal({ progress, token });
return await this.getDatabaseItemInternal(progress);
}
/**
@@ -806,10 +802,10 @@ export class DatabaseUI extends DisposableObject {
* notification if it tries to perform any long-running operations.
*/
private async getDatabaseItemInternal(
progressContext: ProgressContext | undefined,
progress: ProgressCallback | undefined,
): Promise<DatabaseItem | undefined> {
if (this.databaseManager.currentDatabaseItem === undefined) {
progressContext?.progress({
progress?.({
maxStep: 2,
step: 1,
message: "Choosing database",

View File

@@ -290,14 +290,8 @@ export class LocalQueries extends DisposableObject {
private async quickQuery(): Promise<void> {
await withProgress(
async (progress, token) =>
displayQuickQuery(
this.app,
this.cliServer,
this.databaseUI,
progress,
token,
),
async (progress) =>
displayQuickQuery(this.app, this.cliServer, this.databaseUI, progress),
{
title: "Run Quick Query",
},
@@ -445,7 +439,7 @@ export class LocalQueries extends DisposableObject {
// If no databaseItem is specified, use the database currently selected in the Databases UI
databaseItem =
databaseItem ?? (await this.databaseUI.getDatabaseItem(progress, token));
databaseItem ?? (await this.databaseUI.getDatabaseItem(progress));
if (databaseItem === undefined) {
throw new Error("Can't run query without a selected database");
}

View File

@@ -1,7 +1,6 @@
import { ensureDir, writeFile, pathExists, readFile } from "fs-extra";
import { dump, load } from "js-yaml";
import { basename, join } from "path";
import type { CancellationToken } from "vscode";
import { window as Window, workspace, Uri } from "vscode";
import { LSPErrorCodes, ResponseError } from "vscode-languageclient";
import type { CodeQLCliServer } from "../codeql-cli/cli";
@@ -56,7 +55,6 @@ export async function displayQuickQuery(
cliServer: CodeQLCliServer,
databaseUI: DatabaseUI,
progress: ProgressCallback,
token: CancellationToken,
) {
try {
// If there is already a quick query open, don't clobber it, just
@@ -111,7 +109,7 @@ export async function displayQuickQuery(
}
// We're going to infer which qlpack to use from the current database
const dbItem = await databaseUI.getDatabaseItem(progress, token);
const dbItem = await databaseUI.getDatabaseItem(progress);
if (dbItem === undefined) {
throw new Error("Can't start quick query without a selected database");
}

View File

@@ -7,7 +7,7 @@ import {
createFileSync,
pathExistsSync,
} from "fs-extra";
import { CancellationTokenSource, Uri, window } from "vscode";
import { Uri, window } from "vscode";
import type {
DatabaseImportQuickPickItems,
@@ -127,7 +127,6 @@ describe("local-databases-ui", () => {
describe("getDatabaseItem", () => {
const progress = jest.fn();
const token = new CancellationTokenSource().token;
describe("when there is a current database", () => {
const databaseUI = new DatabaseUI(
app,
@@ -153,7 +152,7 @@ describe("local-databases-ui", () => {
);
it("should return current database", async () => {
const databaseItem = await databaseUI.getDatabaseItem(progress, token);
const databaseItem = await databaseUI.getDatabaseItem(progress);
expect(databaseItem).toEqual({ databaseUri: Uri.file(db1) });
});
@@ -211,7 +210,7 @@ describe("local-databases-ui", () => {
"setCurrentDatabaseItem",
);
await databaseUI.getDatabaseItem(progress, token);
await databaseUI.getDatabaseItem(progress);
expect(showQuickPickSpy).toHaveBeenCalledTimes(2);
expect(setCurrentDatabaseItemSpy).toHaveBeenCalledWith({
@@ -241,7 +240,7 @@ describe("local-databases-ui", () => {
.spyOn(databaseUI as any, "handleChooseDatabaseGithub")
.mockResolvedValue(undefined);
await databaseUI.getDatabaseItem(progress, token);
await databaseUI.getDatabaseItem(progress);
expect(showQuickPickSpy).toHaveBeenCalledTimes(2);
expect(handleChooseDatabaseGithubSpy).toHaveBeenCalledTimes(1);
@@ -264,7 +263,7 @@ describe("local-databases-ui", () => {
.spyOn(databaseUI as any, "handleChooseDatabaseGithub")
.mockResolvedValue(undefined);
await databaseUI.getDatabaseItem(progress, token);
await databaseUI.getDatabaseItem(progress);
expect(showQuickPickSpy).toHaveBeenCalledTimes(1);
expect(handleChooseDatabaseGithubSpy).toHaveBeenCalledTimes(1);