Merge pull request #2963 from github/nora/cancel-code-search

Improve code search cancelling
This commit is contained in:
Nora
2023-10-13 10:23:02 +02:00
committed by GitHub
2 changed files with 7 additions and 14 deletions

View File

@@ -4,6 +4,7 @@ import { Progress, CancellationToken } from "vscode";
import { Credentials } from "../common/authentication";
import { BaseLogger } from "../common/logging";
import { AppOctokit } from "../common/octokit";
import { UserCancellationException } from "../common/vscode/progress";
export async function getCodeSearchRepositories(
query: string,
@@ -15,7 +16,7 @@ export async function getCodeSearchRepositories(
credentials: Credentials,
logger: BaseLogger,
): Promise<string[]> {
let nwos: string[] = [];
const nwos: string[] = [];
const octokit = await provideOctokitWithThrottling(credentials, logger);
for await (const response of octokit.paginate.iterator(
@@ -34,8 +35,7 @@ export async function getCodeSearchRepositories(
progress.report({ increment });
if (token.isCancellationRequested) {
nwos = [];
break;
throw new UserCancellationException("Code search cancelled.", true);
}
}

View File

@@ -34,10 +34,7 @@ import { DatabasePanelCommands } from "../../common/commands";
import { App } from "../../common/app";
import { QueryLanguage } from "../../common/query-language";
import { getCodeSearchRepositories } from "../code-search-api";
import {
showAndLogErrorMessage,
showAndLogInformationMessage,
} from "../../common/logging";
import { showAndLogErrorMessage } from "../../common/logging";
export interface RemoteDatabaseQuickPickItem extends QuickPickItem {
remoteDatabaseKind: string;
@@ -426,13 +423,9 @@ export class DbPanel extends DisposableObject {
this.app.logger,
);
token.onCancellationRequested(() => {
void showAndLogInformationMessage(
this.app.logger,
"Code search cancelled",
);
return;
});
if (token.isCancellationRequested) {
throw new UserCancellationException("Code search cancelled.", true);
}
progress.report({ increment: 10, message: "Processing results..." });