🎨 add AbortSignal to indexing

This commit is contained in:
Nate Sesti 2024-04-10 18:23:40 -07:00
parent 3fd0141dba
commit 3eee31a2c4
4 changed files with 19 additions and 1 deletions

View file

@ -59,6 +59,7 @@ export class CodebaseIndexer {
async *refresh(
workspaceDirs: string[],
abortSignal: AbortSignal,
): AsyncGenerator<IndexingProgressUpdate> {
const config = await this.configHandler.loadConfig();
if (config.disableIndexing) {
@ -102,6 +103,13 @@ export class CodebaseIndexer {
repoName,
)) {
// Handle pausing in this loop because it's the only one really taking time
if (abortSignal.aborted) {
yield {
progress: 1,
desc: "Indexing cancelled",
};
return;
}
while (this.pauseToken.paused) {
await new Promise((resolve) => setTimeout(resolve, 100));
}

View file

@ -258,9 +258,17 @@ export class VsCodeExtension {
static continueVirtualDocumentScheme = "continue";
private PREVIOUS_BRANCH_FOR_WORKSPACE_DIR: { [dir: string]: string } = {};
private indexingCancellationController: AbortController | undefined;
private async refreshCodebaseIndex(dirs: string[]) {
for await (const update of this.indexer.refresh(dirs)) {
if (this.indexingCancellationController) {
this.indexingCancellationController.abort();
}
this.indexingCancellationController = new AbortController();
for await (const update of this.indexer.refresh(
dirs,
this.indexingCancellationController.signal,
)) {
this.webviewProtocol.request("indexProgress", update);
}
}

View file

@ -132,6 +132,7 @@ Alternatively, you can enter your own API keys:
});
postToIde("openConfigJson", undefined);
setLocalStorage("onboardingComplete", true);
postToIde("index/forceReIndex", undefined);
navigate("/");
}}
>

View file

@ -117,6 +117,7 @@ function Onboarding() {
mode: ["local", "optimized", "custom"][selected] as any,
});
setLocalStorage("onboardingComplete", true);
postToIde("index/forceReIndex", undefined);
navigate("/");
}}
>