🎨 refactor indexing state into a single object
This commit is contained in:
parent
46fa021f21
commit
2ba12638e4
18 changed files with 24637 additions and 1713 deletions
2
core/index.d.ts
vendored
2
core/index.d.ts
vendored
|
|
@ -37,7 +37,7 @@ export interface Chunk extends ChunkWithoutID {
|
|||
export interface IndexingProgressUpdate {
|
||||
progress: number;
|
||||
desc: string;
|
||||
failed?: boolean;
|
||||
status: "starting" | "indexing" | "done" | "failed" | "paused";
|
||||
}
|
||||
|
||||
export type PromptTemplate =
|
||||
|
|
|
|||
|
|
@ -138,6 +138,7 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex {
|
|||
yield {
|
||||
desc: `Indexing ${compute.path}`,
|
||||
progress: i / results.compute.length,
|
||||
status: "indexing",
|
||||
};
|
||||
markComplete([compute], IndexResultType.Compute);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ export class FullTextSearchCodebaseIndex implements CodebaseIndex {
|
|||
yield {
|
||||
progress: i / results.compute.length,
|
||||
desc: `Indexing ${item.path}`,
|
||||
status: "indexing",
|
||||
};
|
||||
markComplete([item], IndexResultType.Compute);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -250,7 +250,7 @@ export class LanceDbIndex implements CodebaseIndex {
|
|||
data.contents,
|
||||
);
|
||||
|
||||
yield { progress, desc };
|
||||
yield { progress, desc, status: "indexing" };
|
||||
} else {
|
||||
await addComputedLanceDbRows(update, computedRows);
|
||||
computedRows = [];
|
||||
|
|
@ -304,7 +304,11 @@ export class LanceDbIndex implements CodebaseIndex {
|
|||
}
|
||||
|
||||
markComplete(results.del, IndexResultType.Delete);
|
||||
yield { progress: 1, desc: "Completed Calculating Embeddings" };
|
||||
yield {
|
||||
progress: 1,
|
||||
desc: "Completed Calculating Embeddings",
|
||||
status: "done",
|
||||
};
|
||||
}
|
||||
|
||||
private async _retrieveForTag(
|
||||
|
|
|
|||
|
|
@ -113,6 +113,7 @@ export class ChunkCodebaseIndex implements CodebaseIndex {
|
|||
yield {
|
||||
progress: i / results.compute.length,
|
||||
desc: `Chunking ${getBasename(item.path)}`,
|
||||
status: "indexing",
|
||||
};
|
||||
markComplete([item], IndexResultType.Compute);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,8 @@
|
|||
import {
|
||||
Chunk,
|
||||
EmbeddingsProvider,
|
||||
IndexingProgressUpdate,
|
||||
} from "../..";
|
||||
import { Chunk, EmbeddingsProvider, IndexingProgressUpdate } from "../..";
|
||||
|
||||
import { Article, chunkArticle, pageToArticle } from "./article";
|
||||
import { crawlPage } from "./crawl";
|
||||
import { addDocs, hasDoc } from "./db";
|
||||
import { pageToArticle, chunkArticle, Article } from "./article";
|
||||
|
||||
export async function* indexDocs(
|
||||
title: string,
|
||||
|
|
@ -17,6 +13,7 @@ export async function* indexDocs(
|
|||
yield {
|
||||
progress: 1,
|
||||
desc: "Already indexed",
|
||||
status: "done",
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
|
@ -24,19 +21,21 @@ export async function* indexDocs(
|
|||
yield {
|
||||
progress: 0,
|
||||
desc: "Finding subpages",
|
||||
status: "indexing",
|
||||
};
|
||||
|
||||
const articles: Article[] = [];
|
||||
|
||||
for await (const page of crawlPage(baseUrl)) {
|
||||
const article = pageToArticle(page);
|
||||
if (!article) continue;
|
||||
if (!article) continue;
|
||||
|
||||
articles.push(article);
|
||||
|
||||
yield {
|
||||
progress: 0,
|
||||
desc: `Finding subpages (${page.path})`,
|
||||
status: "indexing",
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -47,14 +46,15 @@ export async function* indexDocs(
|
|||
yield {
|
||||
progress: Math.max(1, Math.floor(100 / (articles.length + 1))),
|
||||
desc: `${article.subpath}`,
|
||||
status: "indexing",
|
||||
};
|
||||
|
||||
const subpathEmbeddings = await embeddingsProvider.embed(
|
||||
chunkArticle(article).map(chunk => {
|
||||
chunkArticle(article).map((chunk) => {
|
||||
chunks.push(chunk);
|
||||
|
||||
return chunk.content;
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
embeddings.push(...subpathEmbeddings);
|
||||
|
|
@ -65,5 +65,6 @@ export async function* indexDocs(
|
|||
yield {
|
||||
progress: 1,
|
||||
desc: "Done",
|
||||
status: "done",
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import { getComputeDeleteAddRemove } from "./refreshIndex";
|
|||
import { CodebaseIndex } from "./types";
|
||||
|
||||
export class PauseToken {
|
||||
constructor(private _paused: boolean) { }
|
||||
constructor(private _paused: boolean) {}
|
||||
|
||||
set paused(value: boolean) {
|
||||
this._paused = value;
|
||||
|
|
@ -70,14 +70,6 @@ export class CodebaseIndexer {
|
|||
return;
|
||||
}
|
||||
|
||||
//Test to see if embeddings provider is configured properly
|
||||
try {
|
||||
await config.embeddingsProvider.embed(['sample text']);
|
||||
} catch (error) {
|
||||
yield { progress: 1, desc: "Indexing failed while testing provider", failed: true };
|
||||
return
|
||||
}
|
||||
|
||||
const indexesToBuild = await this.getIndexesToBuild();
|
||||
|
||||
let completedDirs = 0;
|
||||
|
|
@ -89,7 +81,7 @@ export class CodebaseIndexer {
|
|||
yield {
|
||||
progress: 0,
|
||||
desc: "Starting indexing...",
|
||||
failed: false
|
||||
status: "starting",
|
||||
};
|
||||
|
||||
for (let directory of workspaceDirs) {
|
||||
|
|
@ -124,7 +116,7 @@ export class CodebaseIndexer {
|
|||
yield {
|
||||
progress: 1,
|
||||
desc: "Indexing cancelled",
|
||||
failed: true
|
||||
status: "failed",
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
|
@ -138,6 +130,7 @@ export class CodebaseIndexer {
|
|||
(completedIndexes + progress) / indexesToBuild.length) /
|
||||
workspaceDirs.length,
|
||||
desc,
|
||||
status: "indexing",
|
||||
};
|
||||
}
|
||||
completedIndexes++;
|
||||
|
|
@ -146,6 +139,7 @@ export class CodebaseIndexer {
|
|||
(completedDirs + completedIndexes / indexesToBuild.length) /
|
||||
workspaceDirs.length,
|
||||
desc: "Completed indexing " + codebaseIndex.artifactId,
|
||||
status: "indexing",
|
||||
};
|
||||
} catch (e) {
|
||||
console.warn(
|
||||
|
|
@ -158,6 +152,7 @@ export class CodebaseIndexer {
|
|||
yield {
|
||||
progress: completedDirs / workspaceDirs.length,
|
||||
desc: "Indexing Complete",
|
||||
status: "done",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -356,7 +356,7 @@ export class GlobalCacheCodeBaseIndex implements CodebaseIndex {
|
|||
return this.deleteOrRemoveTag(cacheKey, tag);
|
||||
}),
|
||||
]);
|
||||
yield { progress: 1, desc: "Done updating global cache" };
|
||||
yield { progress: 1, desc: "Done updating global cache", status: "done" };
|
||||
}
|
||||
|
||||
private async computeOrAddTag(
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import {
|
|||
ContinueRcJson,
|
||||
DiffLine,
|
||||
IndexTag,
|
||||
IndexingProgressUpdate,
|
||||
Problem,
|
||||
Range,
|
||||
Thread,
|
||||
|
|
@ -75,7 +76,6 @@ export type WebviewProtocol = Protocol &
|
|||
errorPopup: [{ message: string }, void];
|
||||
"index/setPaused": [boolean, void];
|
||||
"index/forceReIndex": [undefined, void];
|
||||
"index/indexingProgressBarInitialized": [{ready: boolean}, void]
|
||||
openUrl: [string, void];
|
||||
applyToCurrentFile: [{ text: string }, void];
|
||||
showTutorial: [undefined, void];
|
||||
|
|
@ -129,8 +129,7 @@ export type ReverseWebviewProtocol = {
|
|||
addModel: [undefined, void];
|
||||
openSettings: [undefined, void];
|
||||
viewHistory: [undefined, void];
|
||||
indexProgress: [{ progress: number; desc: string; failed?: boolean }, void];
|
||||
indexingProgressBarInitialized: [{ready: boolean}, void]
|
||||
indexProgress: [IndexingProgressUpdate, void];
|
||||
newSession: [undefined, void];
|
||||
refreshSubmenuItems: [undefined, void];
|
||||
setTheme: [{ theme: any }, void];
|
||||
|
|
|
|||
16011
extensions/vscode/package-lock.json
generated
Normal file
16011
extensions/vscode/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -114,14 +114,7 @@ export class VsCodeExtension {
|
|||
.getWorkspaceDirs()
|
||||
.then((dirs) => this.refreshCodebaseIndex(dirs, context));
|
||||
});
|
||||
this.webviewProtocol.on("index/indexingProgressBarInitialized", (msg) => {
|
||||
// Triggered when progress bar is initialized. Purpose: To relay global state values to the progress bar
|
||||
let progress = context.globalState.get<number>("continue.indexingProgress") as number
|
||||
let desc = context.globalState.get<string>("continue.indexingDesc") as string
|
||||
let failed = context.globalState.get<boolean>("continue.indexingFailed") as boolean
|
||||
this.webviewProtocol?.request("indexProgress", {progress, desc, failed})
|
||||
});
|
||||
|
||||
|
||||
this.diffManager.webviewProtocol = this.webviewProtocol;
|
||||
|
||||
const userTokenPromise: Promise<string | undefined> = new Promise(
|
||||
|
|
@ -196,7 +189,9 @@ export class VsCodeExtension {
|
|||
registerDebugTracker(this.webviewProtocol, this.ide);
|
||||
|
||||
// Indexing
|
||||
this.ide.getWorkspaceDirs().then((dirs) => this.refreshCodebaseIndex(dirs, context));
|
||||
this.ide
|
||||
.getWorkspaceDirs()
|
||||
.then((dirs) => this.refreshCodebaseIndex(dirs, context));
|
||||
|
||||
// Listen for file saving - use global file watcher so that changes
|
||||
// from outside the window are also caught
|
||||
|
|
@ -274,39 +269,38 @@ export class VsCodeExtension {
|
|||
private PREVIOUS_BRANCH_FOR_WORKSPACE_DIR: { [dir: string]: string } = {};
|
||||
private indexingCancellationController: AbortController | undefined;
|
||||
|
||||
private async refreshCodebaseIndex(dirs: string[], context: vscode.ExtensionContext) {
|
||||
private async refreshCodebaseIndex(
|
||||
dirs: string[],
|
||||
context: vscode.ExtensionContext,
|
||||
) {
|
||||
//reset all state variables
|
||||
console.log("Codebase indexing starting up")
|
||||
this.webviewProtocol?.request("indexProgress", {progress: 0, desc: "", failed:false});
|
||||
context.globalState.update("continue.indexingFailed", false)
|
||||
context.globalState.update("continue.indexingProgress", 0)
|
||||
context.globalState.update("continue.indexingDesc", "")
|
||||
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", "");
|
||||
|
||||
if (this.indexingCancellationController) {
|
||||
this.indexingCancellationController.abort();
|
||||
}
|
||||
this.indexingCancellationController = new AbortController();
|
||||
let err = undefined
|
||||
let err = undefined;
|
||||
for await (const update of this.indexer.refresh(
|
||||
dirs,
|
||||
this.indexingCancellationController.signal,
|
||||
)) {
|
||||
this.webviewProtocol.request("indexProgress", update);
|
||||
if (update.failed) {
|
||||
err = update.desc
|
||||
context.globalState.update("continue.indexingFailed", true)
|
||||
break
|
||||
} else {
|
||||
context.globalState.update("continue.indexingProgress", update.progress)
|
||||
context.globalState.update("continue.indexingDesc", update.desc)
|
||||
}
|
||||
context.globalState.update("continue.indexingProgress", update);
|
||||
}
|
||||
|
||||
if (err) {
|
||||
console.log("Codebase Indexing Failed: ", err)
|
||||
console.log("Codebase Indexing Failed: ", err);
|
||||
} else {
|
||||
console.log("Codebase Indexing Complete")
|
||||
console.log("Codebase Indexing Complete");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
6929
gui/package-lock.json
generated
Normal file
6929
gui/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -2,6 +2,7 @@ import {
|
|||
Cog6ToothIcon,
|
||||
QuestionMarkCircleIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { IndexingProgressUpdate } from "core";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { Outlet, useLocation, useNavigate } from "react-router-dom";
|
||||
|
|
@ -163,9 +164,7 @@ const Layout = () => {
|
|||
);
|
||||
|
||||
useWebviewListener("indexProgress", async (data) => {
|
||||
setIndexingProgress(data.progress);
|
||||
setIndexingTask(data.desc);
|
||||
setIndexingFailed(data.failed)
|
||||
setIndexingState(data);
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -186,9 +185,11 @@ const Layout = () => {
|
|||
}
|
||||
}, [location]);
|
||||
|
||||
const [indexingProgress, setIndexingProgress] = useState(-1);
|
||||
const [indexingTask, setIndexingTask] = useState("Indexing Codebase");
|
||||
const [indexingFailed, setIndexingFailed] = useState(false);
|
||||
const [indexingState, setIndexingState] = useState<IndexingProgressUpdate>({
|
||||
desc: "Starting indexing",
|
||||
progress: 0.0,
|
||||
status: "starting",
|
||||
});
|
||||
|
||||
return (
|
||||
<LayoutTopDiv>
|
||||
|
|
@ -246,7 +247,7 @@ const Layout = () => {
|
|||
/>
|
||||
)} */}
|
||||
<ModelSelect />
|
||||
{indexingProgress >= 1 && // Would take up too much space together with indexing progress
|
||||
{indexingState.status !== "indexing" && // Would take up too much space together with indexing progress
|
||||
defaultModel?.provider === "free-trial" &&
|
||||
(location.pathname === "/settings" ||
|
||||
parseInt(localStorage.getItem("ftc") || "0") >= 50) && (
|
||||
|
|
@ -257,12 +258,7 @@ const Layout = () => {
|
|||
)}
|
||||
|
||||
{isJetBrains() || (
|
||||
<IndexingProgressBar
|
||||
currentlyIndexing={indexingTask}
|
||||
completed={indexingProgress * 100}
|
||||
total={100}
|
||||
indexingFailed={indexingFailed}
|
||||
/>
|
||||
<IndexingProgressBar indexingState={indexingState} />
|
||||
)}
|
||||
</div>
|
||||
<HeaderButtonWithText
|
||||
|
|
|
|||
|
|
@ -167,6 +167,8 @@ const TooltipStyles = {
|
|||
padding: "2px 6px",
|
||||
zIndex: 1000,
|
||||
maxWidth: "80vw",
|
||||
textAlign: "center",
|
||||
overflow: "hidden",
|
||||
};
|
||||
|
||||
export function StyledTooltip(props) {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { IndexingProgressUpdate } from "core";
|
||||
import { useEffect, useState } from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import styled from "styled-components";
|
||||
|
|
@ -49,29 +50,20 @@ const P = styled.p`
|
|||
`;
|
||||
|
||||
interface ProgressBarProps {
|
||||
completed: number;
|
||||
total: number;
|
||||
currentlyIndexing?: string;
|
||||
indexingFailed?: boolean;
|
||||
indexingState: IndexingProgressUpdate;
|
||||
}
|
||||
|
||||
const IndexingProgressBar = ({
|
||||
completed,
|
||||
total,
|
||||
currentlyIndexing,
|
||||
indexingFailed = false
|
||||
}: ProgressBarProps) => {
|
||||
const fillPercentage = Math.min(100, Math.max(0, (completed / total) * 100));
|
||||
const IndexingProgressBar = ({ indexingState }: ProgressBarProps) => {
|
||||
const fillPercentage = Math.min(
|
||||
100,
|
||||
Math.max(0, indexingState.progress * 100),
|
||||
);
|
||||
|
||||
const tooltipPortalDiv = document.getElementById("tooltip-portal-div");
|
||||
|
||||
const [expanded, setExpanded] = useState(true);
|
||||
const [hovered, setHovered] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
postToIde("index/indexingProgressBarInitialized", {ready:true})
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
postToIde("index/setPaused", !expanded);
|
||||
}, [expanded]);
|
||||
|
|
@ -79,7 +71,11 @@ const IndexingProgressBar = ({
|
|||
return (
|
||||
<div
|
||||
onClick={() => {
|
||||
if (!indexingFailed && completed < total && completed >= 0) {
|
||||
if (
|
||||
indexingState.status !== "failed" &&
|
||||
indexingState.progress < 1 &&
|
||||
indexingState.progress >= 0
|
||||
) {
|
||||
setExpanded((prev) => !prev);
|
||||
} else {
|
||||
postToIde("index/forceReIndex", undefined);
|
||||
|
|
@ -87,30 +83,37 @@ const IndexingProgressBar = ({
|
|||
}}
|
||||
className="cursor-pointer"
|
||||
>
|
||||
{
|
||||
(completed < 0 && !indexingFailed) ? ( // ice-blue 'indexing starting up' dot
|
||||
{indexingState.status === "starting" ? ( // ice-blue 'indexing starting up' dot
|
||||
<>
|
||||
<CircleDiv data-tooltip-id="indexingNotLoaded_dot" color="#72aec2"></CircleDiv>
|
||||
{tooltipPortalDiv &&
|
||||
ReactDOM.createPortal(
|
||||
<StyledTooltip id="indexingNotLoaded_dot" place="top">
|
||||
Codebase indexing is starting up.
|
||||
</StyledTooltip>,
|
||||
tooltipPortalDiv,
|
||||
)}
|
||||
<CircleDiv
|
||||
data-tooltip-id="indexingNotLoaded_dot"
|
||||
color="#72aec2"
|
||||
></CircleDiv>
|
||||
{tooltipPortalDiv &&
|
||||
ReactDOM.createPortal(
|
||||
<StyledTooltip id="indexingNotLoaded_dot" place="top">
|
||||
Codebase indexing is starting up.
|
||||
</StyledTooltip>,
|
||||
tooltipPortalDiv,
|
||||
)}
|
||||
</>
|
||||
) : indexingFailed ? ( //red 'failed' dot
|
||||
) : indexingState.status === "failed" ? ( //red 'failed' dot
|
||||
<>
|
||||
<CircleDiv data-tooltip-id="indexingFailed_dot" color="#ff0000"></CircleDiv>
|
||||
{tooltipPortalDiv &&
|
||||
ReactDOM.createPortal(
|
||||
<StyledTooltip id="indexingFailed_dot" place="top">
|
||||
Codebase not indexed. Click to retry
|
||||
</StyledTooltip>,
|
||||
tooltipPortalDiv,
|
||||
)}
|
||||
<CircleDiv
|
||||
data-tooltip-id="indexingFailed_dot"
|
||||
color="#ff0000"
|
||||
></CircleDiv>
|
||||
{tooltipPortalDiv &&
|
||||
ReactDOM.createPortal(
|
||||
<StyledTooltip id="indexingFailed_dot" place="top">
|
||||
Error indexing codebase: {indexingState.desc}
|
||||
<br />
|
||||
Click to retry
|
||||
</StyledTooltip>,
|
||||
tooltipPortalDiv,
|
||||
)}
|
||||
</>
|
||||
) : completed >= total ? ( //indexing complete green dot
|
||||
) : indexingState.status === "done" ? ( //indexing complete green dot
|
||||
<>
|
||||
<CircleDiv data-tooltip-id="progress_dot" color="#090"></CircleDiv>
|
||||
{tooltipPortalDiv &&
|
||||
|
|
@ -134,25 +137,26 @@ const IndexingProgressBar = ({
|
|||
<P>
|
||||
{hovered
|
||||
? "Click to pause"
|
||||
: `Indexing (${Math.trunc((completed / total) * 100)}%)`}
|
||||
: `Indexing (${Math.trunc(indexingState.progress * 100)}%)`}
|
||||
</P>
|
||||
</GridDiv>
|
||||
{tooltipPortalDiv &&
|
||||
ReactDOM.createPortal(
|
||||
<StyledTooltip id="usage_progress_bar" place="top">
|
||||
{currentlyIndexing}
|
||||
{indexingState.desc}
|
||||
</StyledTooltip>,
|
||||
tooltipPortalDiv,
|
||||
)}
|
||||
</>
|
||||
) : ( //yellow 'paused' dot
|
||||
) : (
|
||||
//yellow 'paused' dot
|
||||
<>
|
||||
<CircleDiv data-tooltip-id="progress_dot" color="#bb0"></CircleDiv>
|
||||
{tooltipPortalDiv &&
|
||||
ReactDOM.createPortal(
|
||||
<StyledTooltip id="progress_dot" place="top">
|
||||
Click to unpause indexing (
|
||||
{Math.trunc((completed / total) * 100)}%)
|
||||
{Math.trunc(indexingState.progress * 100)}%)
|
||||
</StyledTooltip>,
|
||||
tooltipPortalDiv,
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { JSONContent } from "@tiptap/react";
|
||||
import { IndexingProgressUpdate } from "core";
|
||||
|
||||
type LocalStorageTypes = {
|
||||
onboardingComplete: boolean;
|
||||
|
|
@ -6,6 +7,7 @@ type LocalStorageTypes = {
|
|||
lastSessionId: string | undefined;
|
||||
inputHistory: JSONContent[];
|
||||
extensionVersion: string;
|
||||
indexingState: IndexingProgressUpdate;
|
||||
};
|
||||
|
||||
export function getLocalStorage<T extends keyof LocalStorageTypes>(
|
||||
|
|
|
|||
1054
gui/yarn.lock
1054
gui/yarn.lock
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue