Skip to content

Commit ee630b4

Browse files
authored
Merge pull request #2963 from github/nora/cancel-code-search
Improve code search cancelling
2 parents fa9cc7c + 43bc92e commit ee630b4

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

extensions/ql-vscode/src/databases/code-search-api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Progress, CancellationToken } from "vscode";
44
import { Credentials } from "../common/authentication";
55
import { BaseLogger } from "../common/logging";
66
import { AppOctokit } from "../common/octokit";
7+
import { UserCancellationException } from "../common/vscode/progress";
78

89
export async function getCodeSearchRepositories(
910
query: string,
@@ -15,7 +16,7 @@ export async function getCodeSearchRepositories(
1516
credentials: Credentials,
1617
logger: BaseLogger,
1718
): Promise<string[]> {
18-
let nwos: string[] = [];
19+
const nwos: string[] = [];
1920
const octokit = await provideOctokitWithThrottling(credentials, logger);
2021

2122
for await (const response of octokit.paginate.iterator(
@@ -34,8 +35,7 @@ export async function getCodeSearchRepositories(
3435
progress.report({ increment });
3536

3637
if (token.isCancellationRequested) {
37-
nwos = [];
38-
break;
38+
throw new UserCancellationException("Code search cancelled.", true);
3939
}
4040
}
4141

extensions/ql-vscode/src/databases/ui/db-panel.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ import { DatabasePanelCommands } from "../../common/commands";
3434
import { App } from "../../common/app";
3535
import { QueryLanguage } from "../../common/query-language";
3636
import { getCodeSearchRepositories } from "../code-search-api";
37-
import {
38-
showAndLogErrorMessage,
39-
showAndLogInformationMessage,
40-
} from "../../common/logging";
37+
import { showAndLogErrorMessage } from "../../common/logging";
4138

4239
export interface RemoteDatabaseQuickPickItem extends QuickPickItem {
4340
remoteDatabaseKind: string;
@@ -426,13 +423,9 @@ export class DbPanel extends DisposableObject {
426423
this.app.logger,
427424
);
428425

429-
token.onCancellationRequested(() => {
430-
void showAndLogInformationMessage(
431-
this.app.logger,
432-
"Code search cancelled",
433-
);
434-
return;
435-
});
426+
if (token.isCancellationRequested) {
427+
throw new UserCancellationException("Code search cancelled.", true);
428+
}
436429

437430
progress.report({ increment: 10, message: "Processing results..." });
438431

0 commit comments

Comments
 (0)