From b27420981e976a8e98f10d63237c893c1bc8cccb Mon Sep 17 00:00:00 2001 From: chezsmithy Date: Wed, 4 Jun 2025 17:47:48 -0700 Subject: [PATCH] refactor to using CodeBaseIndexer instead of Core --- core/core.ts | 81 +------------------------------------------------ core/index.d.ts | 3 +- 2 files changed, 3 insertions(+), 81 deletions(-) diff --git a/core/core.ts b/core/core.ts index 648b1ed40..992b930eb 100644 --- a/core/core.ts +++ b/core/core.ts @@ -708,7 +708,7 @@ export class Core { tool, toolCallId: toolCall.id, onPartialOutput, - core: this, // Add a reference to the Core instance + codeBaseIndexer: this.codeBaseIndexer, }); }); @@ -1026,83 +1026,4 @@ export class Core { false, ); } - - private async refreshCodebaseIndex(paths: string[]) { - if (this.indexingCancellationController) { - this.indexingCancellationController.abort(); - } - this.indexingCancellationController = new AbortController(); - try { - for await (const update of ( - await this.codebaseIndexerPromise - ).refreshDirs(paths, this.indexingCancellationController.signal)) { - let updateToSend = { ...update }; - - void this.messenger.request("indexProgress", updateToSend); - this.codebaseIndexingState = updateToSend; - - if (update.status === "failed") { - void this.sendIndexingErrorTelemetry(update); - } - } - } catch (e: any) { - console.log(`Failed refreshing codebase index directories : ${e}`); - this.handleIndexingError(e); - } - - this.messenger.send("refreshSubmenuItems", { - providers: "dependsOnIndexing", - }); - this.indexingCancellationController = undefined; - } - - private async refreshCodebaseIndexFiles(files: string[]) { - // Can be cancelled by codebase index but not vice versa - if ( - this.indexingCancellationController && - !this.indexingCancellationController.signal.aborted - ) { - return; - } - this.indexingCancellationController = new AbortController(); - try { - for await (const update of ( - await this.codebaseIndexerPromise - ).refreshFiles(files)) { - let updateToSend = { ...update }; - - void this.messenger.request("indexProgress", updateToSend); - this.codebaseIndexingState = updateToSend; - - if (update.status === "failed") { - void this.sendIndexingErrorTelemetry(update); - } - } - } catch (e: any) { - console.log(`Failed refreshing codebase index files : ${e}`); - this.handleIndexingError(e); - } - - this.messenger.send("refreshSubmenuItems", { - providers: "dependsOnIndexing", - }); - this.indexingCancellationController = undefined; - } - - // private - handleIndexingError(e: any) { - if (e instanceof LLMError) { - // Need to report this specific error to the IDE for special handling - void this.messenger.request("reportError", e); - } - // broadcast indexing error - let updateToSend: IndexingProgressUpdate = { - progress: 0, - status: "failed", - desc: e.message, - }; - void this.messenger.request("indexProgress", updateToSend); - this.codebaseIndexingState = updateToSend; - void this.sendIndexingErrorTelemetry(updateToSend); - } } diff --git a/core/index.d.ts b/core/index.d.ts index 195ab6c47..3613344ea 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -7,6 +7,7 @@ import Parser from "web-tree-sitter"; import { LLMConfigurationStatuses } from "./llm/constants"; import { GetGhTokenArgs } from "./protocol/ide"; import { Core } from "./core"; +import { CodebaseIndexer } from "./indexing/CodebaseIndexer"; declare global { interface Window { @@ -970,7 +971,7 @@ export interface ToolExtras { toolCallId: string; contextItems: ContextItem[]; }) => void; - core?: Core; // Reference to the Core instance + codeBaseIndexer?: CodebaseIndexer; } export interface Tool {