diff --git a/core/core.ts b/core/core.ts index 8fb1686554..ceda3a6796 100644 --- a/core/core.ts +++ b/core/core.ts @@ -25,6 +25,7 @@ import type { IMessenger, Message } from "./util/messenger"; import { editConfigJson, getConfigJsonPath } from "./util/paths"; import { Telemetry } from "./util/posthog"; import { streamDiffLines } from "./util/verticalEdit"; +import { IndexingProgressUpdate } from "."; export class Core { // implements IMessenger @@ -32,6 +33,7 @@ export class Core { codebaseIndexerPromise: Promise; completionProvider: CompletionProvider; continueServerClientPromise: Promise; + indexingState: IndexingProgressUpdate private abortedMessageIds: Set = new Set(); @@ -59,6 +61,7 @@ export class Core { private readonly ide: IDE, private readonly onWrite: (text: string) => Promise = async () => {}, ) { + this.indexingState = { status:"loading", desc: 'loading', progress: 0 } const ideSettingsPromise = messenger.request("getIdeSettings", undefined); this.configHandler = new ConfigHandler( this.ide, @@ -519,6 +522,13 @@ export class Core { new GlobalContext().update("indexingPaused", msg.data); indexingPauseToken.paused = msg.data; }); + on("index/indexingProgressBarInitialized", async (msg) => { + // Triggered when progress bar is initialized. + // If a non-default state has been stored, update the indexing display to that state + if (this.indexingState.status != 'loading') { + this.messenger.request("indexProgress", this.indexingState); + } + }); } private indexingCancellationController: AbortController | undefined; @@ -533,6 +543,7 @@ export class Core { this.indexingCancellationController.signal, )) { this.messenger.request("indexProgress", update); + this.indexingState = update } } } diff --git a/core/index.d.ts b/core/index.d.ts index 859e428c97..ceae7eea3f 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -37,7 +37,7 @@ export interface Chunk extends ChunkWithoutID { export interface IndexingProgressUpdate { progress: number; desc: string; - status: "starting" | "indexing" | "done" | "failed" | "paused" | "disabled"; + status: "loading" | "indexing" | "done" | "failed" | "paused" | "disabled"; } export type PromptTemplate = diff --git a/core/indexing/LanceDbIndex.ts b/core/indexing/LanceDbIndex.ts index da912f5f90..de871e0538 100644 --- a/core/indexing/LanceDbIndex.ts +++ b/core/indexing/LanceDbIndex.ts @@ -148,8 +148,8 @@ export class LanceDbIndex implements CodebaseIndex { // Compute let table: Table | undefined = undefined; - let needToCreateTable = true; const existingTables = await db.tableNames(); + let needToCreateTable = !existingTables.includes(tableName); const addComputedLanceDbRows = async ( pathAndCacheKey: PathAndCacheKey, diff --git a/core/indexing/indexCodebase.ts b/core/indexing/indexCodebase.ts index c5822c3d23..e051dc0011 100644 --- a/core/indexing/indexCodebase.ts +++ b/core/indexing/indexCodebase.ts @@ -56,16 +56,16 @@ export class CodebaseIndexer { yield { progress: 0, desc: "Nothing to index", - status: "disabled", + status: "disabled", }; return; } - + const config = await this.configHandler.loadConfig(); if (config.disableIndexing) { yield { progress: 0, - desc: "Indexing is disabled in the config.json", + desc: "Indexing is disabled in config.json", status: "disabled", }; return; @@ -73,7 +73,7 @@ export class CodebaseIndexer { yield { progress: 0, desc: "Starting indexing", - status: "starting", + status: "loading", }; } @@ -88,7 +88,7 @@ export class CodebaseIndexer { yield { progress: 0, desc: "Starting indexing...", - status: "starting", + status: "loading", }; for (const directory of workspaceDirs) { @@ -161,9 +161,15 @@ export class CodebaseIndexer { status: "indexing", }; } catch (e) { + yield { + progress: 0, + desc: `${e}`, + status: "failed" + } console.warn( `Error updating the ${codebaseIndex.artifactId} index: ${e}`, ); + return } } diff --git a/core/protocol/core.ts b/core/protocol/core.ts index ff5e4cc86b..d6c00dcab1 100644 --- a/core/protocol/core.ts +++ b/core/protocol/core.ts @@ -121,6 +121,7 @@ export type ToCoreFromIdeOrWebviewProtocol = { ]; "index/setPaused": [boolean, void]; "index/forceReIndex": [undefined | string, void]; + "index/indexingProgressBarInitialized": [undefined, void]; completeOnboarding: [ { mode: diff --git a/core/protocol/passThrough.ts b/core/protocol/passThrough.ts index cd7672f89a..005fa912cf 100644 --- a/core/protocol/passThrough.ts +++ b/core/protocol/passThrough.ts @@ -36,6 +36,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] = "stats/getTokensPerModel", "index/setPaused", "index/forceReIndex", + "index/indexingProgressBarInitialized", "completeOnboarding", "addAutocompleteModel", ]; diff --git a/core/util/GlobalContext.ts b/core/util/GlobalContext.ts index b74dd56296..8e514c92f5 100644 --- a/core/util/GlobalContext.ts +++ b/core/util/GlobalContext.ts @@ -1,5 +1,6 @@ import fs from "node:fs"; import { getGlobalContextFilePath } from "./paths"; +import { IndexingProgressUpdate } from ".."; export type GlobalContextType = { indexingPaused: boolean; diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index e621cc33f0..55683b744b 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -223,10 +223,10 @@ const Layout = () => { } }, [location]); - const [indexingState, setIndexingState] = useState({ - desc: "Indexing disabled", + const [indexingState, setIndexingState] = useState({ + desc: "Loading indexing config", progress: 0.0, - status: "disabled", + status: "loading", }); return ( diff --git a/gui/src/components/loaders/IndexingProgressBar.tsx b/gui/src/components/loaders/IndexingProgressBar.tsx index bbad222485..4a68f819ae 100644 --- a/gui/src/components/loaders/IndexingProgressBar.tsx +++ b/gui/src/components/loaders/IndexingProgressBar.tsx @@ -51,10 +51,28 @@ const P = styled.p` `; interface ProgressBarProps { - indexingState: IndexingProgressUpdate; + indexingState?: IndexingProgressUpdate; } -const IndexingProgressBar = ({ indexingState }: ProgressBarProps) => { +const IndexingProgressBar = ({ indexingState: indexingStateProp }: ProgressBarProps) => { + // If sidebar is opened before extension initiates, define a default indexingState + const defaultIndexingState: IndexingProgressUpdate = { + status: 'loading', + progress: 0, + desc: '' + }; + const indexingState = indexingStateProp || defaultIndexingState; + + // If sidebar is opened after extension initializes, retrieve saved states. + let initialized = false + useEffect(() => { + if (!initialized) { + // Triggers retrieval for possible non-default states set prior to IndexingProgressBar initialization + ideMessenger.post("index/indexingProgressBarInitialized", undefined) + initialized = true + } + }, []); + const fillPercentage = Math.min( 100, Math.max(0, indexingState.progress * 100), @@ -87,7 +105,7 @@ const IndexingProgressBar = ({ indexingState }: ProgressBarProps) => { }} className="cursor-pointer" > - {indexingState.status === "starting" ? ( // ice-blue 'indexing starting up' dot + {indexingState.status === "loading" ? ( // ice-blue 'indexing loading' dot <> { {tooltipPortalDiv && ReactDOM.createPortal( - Codebase indexing is starting up. + Continue is initializing , tooltipPortalDiv, )}