From be741acf9f0726283ba5ac4cd70228697c101cd5 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 15 May 2024 18:37:08 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20indexing=20status=20displa?= =?UTF-8?q?y?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/index.d.ts | 2 +- core/indexing/indexCodebase.ts | 30 ++++++++- .../vscode/src/extension/vscodeExtension.ts | 18 +++--- gui/src/components/Layout.tsx | 4 +- .../loaders/IndexingProgressBar.tsx | 63 +++++++++++++------ 5 files changed, 81 insertions(+), 36 deletions(-) diff --git a/core/index.d.ts b/core/index.d.ts index dd07e2505..0fd18496a 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"; + status: "starting" | "indexing" | "done" | "failed" | "paused" | "disabled"; } export type PromptTemplate = diff --git a/core/indexing/indexCodebase.ts b/core/indexing/indexCodebase.ts index 92b4fd5fa..084add74c 100644 --- a/core/indexing/indexCodebase.ts +++ b/core/indexing/indexCodebase.ts @@ -53,12 +53,28 @@ export class CodebaseIndexer { abortSignal: AbortSignal, ): AsyncGenerator { if (workspaceDirs.length === 0) { + yield { + progress: 0, + desc: "Nothing to index", + status: "disabled", + }; return; } const config = await this.configHandler.loadConfig(); if (config.disableIndexing) { + yield { + progress: 0, + desc: "Indexing is disabled in the config.json", + status: "disabled", + }; return; + } else { + yield { + progress: 0, + desc: "Starting indexing", + status: "starting", + }; } const indexesToBuild = await this.getIndexesToBuild(); @@ -107,12 +123,20 @@ export class CodebaseIndexer { yield { progress: 1, desc: "Indexing cancelled", - status: "failed", + status: "disabled", }; return; } - while (this.pauseToken.paused) { - await new Promise((resolve) => setTimeout(resolve, 100)); + + if (this.pauseToken.paused) { + yield { + progress: completedDirs / workspaceDirs.length, + desc: "Paused", + status: "paused", + }; + while (this.pauseToken.paused) { + await new Promise((resolve) => setTimeout(resolve, 100)); + } } yield { diff --git a/extensions/vscode/src/extension/vscodeExtension.ts b/extensions/vscode/src/extension/vscodeExtension.ts index ba15c0c25..3af8d8713 100644 --- a/extensions/vscode/src/extension/vscodeExtension.ts +++ b/extensions/vscode/src/extension/vscodeExtension.ts @@ -279,21 +279,17 @@ export class VsCodeExtension { dirs: string[], context: vscode.ExtensionContext, ) { - //reset all state variables - console.log("Codebase indexing starting up"); - this.webviewProtocol?.request("indexProgress", { - progress: 0, - desc: "", - status: "failed", - }); - context.globalState.update("continue.indexingFailed", false); - context.globalState.update("continue.indexingProgress", 0); - context.globalState.update("continue.indexingDesc", ""); - + // Cancel previous indexing job if it exists if (this.indexingCancellationController) { this.indexingCancellationController.abort(); } this.indexingCancellationController = new AbortController(); + + //reset all state variables + context.globalState.update("continue.indexingFailed", false); + context.globalState.update("continue.indexingProgress", 0); + context.globalState.update("continue.indexingDesc", ""); + let err = undefined; for await (const update of this.indexer.refresh( dirs, diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index f00b0a023..d3bd31259 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -186,9 +186,9 @@ const Layout = () => { }, [location]); const [indexingState, setIndexingState] = useState({ - desc: "Starting indexing", + desc: "Indexing disabled", progress: 0.0, - status: "starting", + status: "disabled", }); return ( diff --git a/gui/src/components/loaders/IndexingProgressBar.tsx b/gui/src/components/loaders/IndexingProgressBar.tsx index c3fb10299..fe01d0413 100644 --- a/gui/src/components/loaders/IndexingProgressBar.tsx +++ b/gui/src/components/loaders/IndexingProgressBar.tsx @@ -62,12 +62,13 @@ const IndexingProgressBar = ({ indexingState }: ProgressBarProps) => { const tooltipPortalDiv = document.getElementById("tooltip-portal-div"); - const [expanded, setExpanded] = useState(true); + const [paused, setPaused] = useState(undefined); const [hovered, setHovered] = useState(false); useEffect(() => { - postToIde("index/setPaused", !expanded); - }, [expanded]); + if (paused === undefined) return; + postToIde("index/setPaused", paused); + }, [paused]); return (
{ indexingState.progress < 1 && indexingState.progress >= 0 ) { - setExpanded((prev) => !prev); + setPaused((prev) => !prev); } else { postToIde("index/forceReIndex", undefined); } @@ -125,12 +126,49 @@ const IndexingProgressBar = ({ indexingState }: ProgressBarProps) => { tooltipPortalDiv, )} - ) : expanded ? ( //progress bar + ) : indexingState.status === "disabled" ? ( //gray disabled dot + <> + + {tooltipPortalDiv && + ReactDOM.createPortal( + + {indexingState.desc} + , + tooltipPortalDiv, + )} + + ) : indexingState.status === "paused" || + (paused && indexingState.status === "indexing") ? ( + //yellow 'paused' dot + <> + { + postToIde("index/setPaused", false); + }} + > + {tooltipPortalDiv && + ReactDOM.createPortal( + + Click to unpause indexing ( + {Math.trunc(indexingState.progress * 100)}%) + , + tooltipPortalDiv, + )} + + ) : indexingState.status === "indexing" ? ( //progress bar <> setHovered(true)} onMouseLeave={() => setHovered(false)} + onClick={(e) => { + postToIde("index/setPaused", true); + }} > @@ -149,20 +187,7 @@ const IndexingProgressBar = ({ indexingState }: ProgressBarProps) => { tooltipPortalDiv, )} - ) : ( - //yellow 'paused' dot - <> - - {tooltipPortalDiv && - ReactDOM.createPortal( - - Click to unpause indexing ( - {Math.trunc(indexingState.progress * 100)}%) - , - tooltipPortalDiv, - )} - - )} + ) : null}
); };