Merge pull request #3517 from github/robertbrignull/fix-token-alerts
Mark progress bars as cancellable where it appears we are respecting the token
This commit is contained in:
@@ -48,7 +48,7 @@ type ProgressOptions = Optional<VSCodeProgressOptions, "location">;
|
|||||||
* denote some progress being achieved on this task.
|
* denote some progress being achieved on this task.
|
||||||
* @param token a cancellation token
|
* @param token a cancellation token
|
||||||
*/
|
*/
|
||||||
export type ProgressTask<R> = (
|
type ProgressTask<R> = (
|
||||||
progress: ProgressCallback,
|
progress: ProgressCallback,
|
||||||
token: CancellationToken,
|
token: CancellationToken,
|
||||||
) => Thenable<R>;
|
) => Thenable<R>;
|
||||||
|
|||||||
@@ -645,14 +645,13 @@ export class DatabaseUI extends DisposableObject {
|
|||||||
|
|
||||||
private async handleClearCache(): Promise<void> {
|
private async handleClearCache(): Promise<void> {
|
||||||
return withProgress(
|
return withProgress(
|
||||||
async (_progress, token) => {
|
async () => {
|
||||||
if (
|
if (
|
||||||
this.queryServer !== undefined &&
|
this.queryServer !== undefined &&
|
||||||
this.databaseManager.currentDatabaseItem !== undefined
|
this.databaseManager.currentDatabaseItem !== undefined
|
||||||
) {
|
) {
|
||||||
await this.queryServer.clearCacheInDatabase(
|
await this.queryServer.clearCacheInDatabase(
|
||||||
this.databaseManager.currentDatabaseItem,
|
this.databaseManager.currentDatabaseItem,
|
||||||
token,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -664,14 +663,13 @@ export class DatabaseUI extends DisposableObject {
|
|||||||
|
|
||||||
private async handleTrimCache(): Promise<void> {
|
private async handleTrimCache(): Promise<void> {
|
||||||
return withProgress(
|
return withProgress(
|
||||||
async (_progress, token) => {
|
async () => {
|
||||||
if (
|
if (
|
||||||
this.queryServer !== undefined &&
|
this.queryServer !== undefined &&
|
||||||
this.databaseManager.currentDatabaseItem !== undefined
|
this.databaseManager.currentDatabaseItem !== undefined
|
||||||
) {
|
) {
|
||||||
await this.queryServer.trimCacheInDatabase(
|
await this.queryServer.trimCacheInDatabase(
|
||||||
this.databaseManager.currentDatabaseItem,
|
this.databaseManager.currentDatabaseItem,
|
||||||
token,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -184,11 +184,11 @@ function getCommands(
|
|||||||
|
|
||||||
const restartQueryServer = async () =>
|
const restartQueryServer = async () =>
|
||||||
withProgress(
|
withProgress(
|
||||||
async (progress: ProgressCallback, token: CancellationToken) => {
|
async (progress: ProgressCallback) => {
|
||||||
// Restart all of the spawned servers: cli, query, and language.
|
// Restart all of the spawned servers: cli, query, and language.
|
||||||
cliServer.restartCliServer();
|
cliServer.restartCliServer();
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
queryRunner.restartQueryServer(progress, token),
|
queryRunner.restartQueryServer(progress),
|
||||||
async () => {
|
async () => {
|
||||||
if (languageClient.isRunning()) {
|
if (languageClient.isRunning()) {
|
||||||
await languageClient.restart();
|
await languageClient.restart();
|
||||||
|
|||||||
@@ -814,58 +814,61 @@ export class ModelEditorView extends AbstractWebview<
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async modelDependency(): Promise<void> {
|
private async modelDependency(): Promise<void> {
|
||||||
return withProgress(async (progress, token) => {
|
return withProgress(
|
||||||
const addedDatabase =
|
async (progress, token) => {
|
||||||
await this.promptChooseNewOrExistingDatabase(progress);
|
const addedDatabase =
|
||||||
if (!addedDatabase || token.isCancellationRequested) {
|
await this.promptChooseNewOrExistingDatabase(progress);
|
||||||
return;
|
if (!addedDatabase || token.isCancellationRequested) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const addedDbUri = addedDatabase.databaseUri.toString();
|
const addedDbUri = addedDatabase.databaseUri.toString();
|
||||||
if (this.modelingStore.isDbOpen(addedDbUri)) {
|
if (this.modelingStore.isDbOpen(addedDbUri)) {
|
||||||
this.modelingEvents.fireFocusModelEditorEvent(addedDbUri);
|
this.modelingEvents.fireFocusModelEditorEvent(addedDbUri);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const modelFile = await pickExtensionPack(
|
const modelFile = await pickExtensionPack(
|
||||||
this.cliServer,
|
this.cliServer,
|
||||||
addedDatabase,
|
addedDatabase,
|
||||||
this.modelConfig,
|
this.modelConfig,
|
||||||
this.app.logger,
|
this.app.logger,
|
||||||
progress,
|
progress,
|
||||||
token,
|
token,
|
||||||
3,
|
3,
|
||||||
);
|
);
|
||||||
if (!modelFile) {
|
if (!modelFile) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check again just before opening the editor to ensure no model editor has been opened between
|
// Check again just before opening the editor to ensure no model editor has been opened between
|
||||||
// our first check and now.
|
// our first check and now.
|
||||||
if (this.modelingStore.isDbOpen(addedDbUri)) {
|
if (this.modelingStore.isDbOpen(addedDbUri)) {
|
||||||
this.modelingEvents.fireFocusModelEditorEvent(addedDbUri);
|
this.modelingEvents.fireFocusModelEditorEvent(addedDbUri);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const view = new ModelEditorView(
|
const view = new ModelEditorView(
|
||||||
this.app,
|
this.app,
|
||||||
this.modelingStore,
|
this.modelingStore,
|
||||||
this.modelingEvents,
|
this.modelingEvents,
|
||||||
this.modelConfig,
|
this.modelConfig,
|
||||||
this.databaseManager,
|
this.databaseManager,
|
||||||
this.databaseFetcher,
|
this.databaseFetcher,
|
||||||
this.variantAnalysisManager,
|
this.variantAnalysisManager,
|
||||||
this.cliServer,
|
this.cliServer,
|
||||||
this.queryRunner,
|
this.queryRunner,
|
||||||
this.queryStorageDir,
|
this.queryStorageDir,
|
||||||
this.queryDir,
|
this.queryDir,
|
||||||
addedDatabase,
|
addedDatabase,
|
||||||
modelFile,
|
modelFile,
|
||||||
this.language,
|
this.language,
|
||||||
Mode.Framework,
|
Mode.Framework,
|
||||||
);
|
);
|
||||||
await view.openView();
|
await view.openView();
|
||||||
});
|
},
|
||||||
|
{ cancellable: true },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async promptChooseNewOrExistingDatabase(
|
private async promptChooseNewOrExistingDatabase(
|
||||||
|
|||||||
@@ -91,26 +91,15 @@ export class QueryRunner {
|
|||||||
return this.qs.logger;
|
return this.qs.logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
async restartQueryServer(
|
async restartQueryServer(progress: ProgressCallback): Promise<void> {
|
||||||
progress: ProgressCallback,
|
await this.qs.restartQueryServer(progress);
|
||||||
token: CancellationToken,
|
|
||||||
): Promise<void> {
|
|
||||||
await this.qs.restartQueryServer(progress, token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onStart(
|
onStart(callBack: (progress: ProgressCallback) => Promise<void>) {
|
||||||
callBack: (
|
|
||||||
progress: ProgressCallback,
|
|
||||||
token: CancellationToken,
|
|
||||||
) => Promise<void>,
|
|
||||||
) {
|
|
||||||
this.qs.onDidStartQueryServer(callBack);
|
this.qs.onDidStartQueryServer(callBack);
|
||||||
}
|
}
|
||||||
|
|
||||||
async clearCacheInDatabase(
|
async clearCacheInDatabase(dbItem: DatabaseItem): Promise<void> {
|
||||||
dbItem: DatabaseItem,
|
|
||||||
token: CancellationToken,
|
|
||||||
): Promise<void> {
|
|
||||||
if (dbItem.contents === undefined) {
|
if (dbItem.contents === undefined) {
|
||||||
throw new Error("Can't clear the cache in an invalid database.");
|
throw new Error("Can't clear the cache in an invalid database.");
|
||||||
}
|
}
|
||||||
@@ -120,13 +109,10 @@ export class QueryRunner {
|
|||||||
dryRun: false,
|
dryRun: false,
|
||||||
db,
|
db,
|
||||||
};
|
};
|
||||||
await this.qs.sendRequest(clearCache, params, token);
|
await this.qs.sendRequest(clearCache, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
async trimCacheInDatabase(
|
async trimCacheInDatabase(dbItem: DatabaseItem): Promise<void> {
|
||||||
dbItem: DatabaseItem,
|
|
||||||
token: CancellationToken,
|
|
||||||
): Promise<void> {
|
|
||||||
if (dbItem.contents === undefined) {
|
if (dbItem.contents === undefined) {
|
||||||
throw new Error("Can't trim the cache in an invalid database.");
|
throw new Error("Can't trim the cache in an invalid database.");
|
||||||
}
|
}
|
||||||
@@ -135,7 +121,7 @@ export class QueryRunner {
|
|||||||
const params: TrimCacheParams = {
|
const params: TrimCacheParams = {
|
||||||
db,
|
db,
|
||||||
};
|
};
|
||||||
await this.qs.sendRequest(trimCache, params, token);
|
await this.qs.sendRequest(trimCache, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async compileAndRunQueryAgainstDatabaseCore(
|
public async compileAndRunQueryAgainstDatabaseCore(
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import type { ProgressReporter } from "../common/logging/vscode";
|
|||||||
import { extLogger } from "../common/logging/vscode";
|
import { extLogger } from "../common/logging/vscode";
|
||||||
import type { ProgressMessage, WithProgressId } from "./messages";
|
import type { ProgressMessage, WithProgressId } from "./messages";
|
||||||
import { progress } from "./messages";
|
import { progress } from "./messages";
|
||||||
import type { ProgressCallback, ProgressTask } from "../common/vscode/progress";
|
import type { ProgressCallback } from "../common/vscode/progress";
|
||||||
import { withProgress } from "../common/vscode/progress";
|
import { withProgress } from "../common/vscode/progress";
|
||||||
import { ServerProcess } from "./server-process";
|
import { ServerProcess } from "./server-process";
|
||||||
import type { App } from "../common/app";
|
import type { App } from "../common/app";
|
||||||
@@ -51,12 +51,16 @@ export class QueryServerClient extends DisposableObject {
|
|||||||
|
|
||||||
withProgressReporting: WithProgressReporting;
|
withProgressReporting: WithProgressReporting;
|
||||||
|
|
||||||
private readonly queryServerStartListeners = [] as Array<ProgressTask<void>>;
|
private readonly queryServerStartListeners = [] as Array<
|
||||||
|
(progress: ProgressCallback) => void
|
||||||
|
>;
|
||||||
|
|
||||||
// Can't use standard vscode EventEmitter here since they do not cause the calling
|
// Can't use standard vscode EventEmitter here since they do not cause the calling
|
||||||
// function to fail if one of the event handlers fail. This is something that
|
// function to fail if one of the event handlers fail. This is something that
|
||||||
// we need here.
|
// we need here.
|
||||||
readonly onDidStartQueryServer = (e: ProgressTask<void>) => {
|
readonly onDidStartQueryServer = (
|
||||||
|
e: (progress: ProgressCallback) => void,
|
||||||
|
) => {
|
||||||
this.queryServerStartListeners.push(e);
|
this.queryServerStartListeners.push(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -105,14 +109,11 @@ export class QueryServerClient extends DisposableObject {
|
|||||||
* This resets the unexpected termination count. As hopefully it is an indication that the user has fixed the
|
* This resets the unexpected termination count. As hopefully it is an indication that the user has fixed the
|
||||||
* issue.
|
* issue.
|
||||||
*/
|
*/
|
||||||
async restartQueryServer(
|
async restartQueryServer(progress: ProgressCallback): Promise<void> {
|
||||||
progress: ProgressCallback,
|
|
||||||
token: CancellationToken,
|
|
||||||
): Promise<void> {
|
|
||||||
// Reset the unexpected termination count when we restart the query server manually
|
// Reset the unexpected termination count when we restart the query server manually
|
||||||
// or due to config change
|
// or due to config change
|
||||||
this.unexpectedTerminationCount = 0;
|
this.unexpectedTerminationCount = 0;
|
||||||
await this.restartQueryServerInternal(progress, token);
|
await this.restartQueryServerInternal(progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -121,8 +122,7 @@ export class QueryServerClient extends DisposableObject {
|
|||||||
private restartQueryServerOnFailure() {
|
private restartQueryServerOnFailure() {
|
||||||
if (this.unexpectedTerminationCount < MAX_UNEXPECTED_TERMINATIONS) {
|
if (this.unexpectedTerminationCount < MAX_UNEXPECTED_TERMINATIONS) {
|
||||||
void withProgress(
|
void withProgress(
|
||||||
async (progress, token) =>
|
async (progress) => this.restartQueryServerInternal(progress),
|
||||||
this.restartQueryServerInternal(progress, token),
|
|
||||||
{
|
{
|
||||||
title: "Restarting CodeQL query server due to unexpected termination",
|
title: "Restarting CodeQL query server due to unexpected termination",
|
||||||
},
|
},
|
||||||
@@ -144,7 +144,6 @@ export class QueryServerClient extends DisposableObject {
|
|||||||
*/
|
*/
|
||||||
private async restartQueryServerInternal(
|
private async restartQueryServerInternal(
|
||||||
progress: ProgressCallback,
|
progress: ProgressCallback,
|
||||||
token: CancellationToken,
|
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
this.stopQueryServer();
|
this.stopQueryServer();
|
||||||
await this.startQueryServer();
|
await this.startQueryServer();
|
||||||
@@ -152,7 +151,7 @@ export class QueryServerClient extends DisposableObject {
|
|||||||
// Ensure we await all responses from event handlers so that
|
// Ensure we await all responses from event handlers so that
|
||||||
// errors can be properly reported to the user.
|
// errors can be properly reported to the user.
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
this.queryServerStartListeners.map((handler) => handler(progress, token)),
|
this.queryServerStartListeners.map((handler) => handler(progress)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user