diff --git a/core/core.ts b/core/core.ts index 8fb168655..ceda3a679 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 fdff6fd96..29c95145b 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 da912f5f9..de871e053 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 c5822c3d2..e051dc001 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 ff5e4cc86..d6c00dcab 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 cd7672f89..005fa912c 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 b74dd5629..8e514c92f 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/extensions/vscode/scripts/prepackage.js b/extensions/vscode/scripts/prepackage.js index d276ac458..d42a7a21d 100644 --- a/extensions/vscode/scripts/prepackage.js +++ b/extensions/vscode/scripts/prepackage.js @@ -13,6 +13,10 @@ rimrafSync(path.join(__dirname, "..", "out")); fs.mkdirSync(path.join(__dirname, "..", "out", "node_modules"), { recursive: true, }); +const guiDist = path.join(__dirname, "..", "..", "..", "gui", "dist"); +if (!fs.existsSync(guiDist)) { + fs.mkdirSync(guiDist, { recursive: true }); +} // Get the target to package for let target = undefined; diff --git a/extensions/vscode/src/ideProtocol.ts b/extensions/vscode/src/ideProtocol.ts index b1267444b..b05e7183e 100644 --- a/extensions/vscode/src/ideProtocol.ts +++ b/extensions/vscode/src/ideProtocol.ts @@ -14,7 +14,11 @@ import type { } from "core"; import { defaultIgnoreFile } from "core/indexing/ignore"; import { IdeSettings } from "core/protocol/ideWebview"; -import { getContinueGlobalPath } from "core/util/paths"; +import { + editConfigJson, + getConfigJsonPath, + getContinueGlobalPath, +} from "core/util/paths"; import * as vscode from "vscode"; import { DiffManager } from "./diff/horizontal"; import { Repository } from "./otherExtensions/git"; @@ -48,6 +52,28 @@ class VsCodeIde implements IDE { if (session) { this.authToken = session.accessToken; return session.accessToken; + } else if (!this.askedForAuth) { + // User cancelled the login prompt + // Explain that they can avoid the prompt by removing free trial models from config.json + vscode.window + .showInformationMessage( + "We'll only ask you to log in if using the free trial. To avoid this prompt, make sure to remove free trial models from your config.json", + "Remove for me", + "Open config.json", + ) + .then((selection) => { + if (selection === "Remove for me") { + editConfigJson((configJson) => { + configJson.models = configJson.models.filter( + (model) => model.provider !== "free-trial", + ); + configJson.tabAutocompleteModel = undefined; + return configJson; + }); + } else if (selection === "Open config.json") { + this.openFile(getConfigJsonPath()); + } + }); } } catch (error) { console.error("Failed to get GitHub authentication session:", error); diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index e621cc33f..55683b744 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 bbad22248..4a68f819a 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, )} diff --git a/gui/src/components/modelSelection/quickSetup/GitHubSignInButton.tsx b/gui/src/components/modelSelection/quickSetup/GitHubSignInButton.tsx index e362bb8a8..fb0419f53 100644 --- a/gui/src/components/modelSelection/quickSetup/GitHubSignInButton.tsx +++ b/gui/src/components/modelSelection/quickSetup/GitHubSignInButton.tsx @@ -3,6 +3,7 @@ import { useNavigate } from "react-router-dom"; import { Button, Input, SecondaryButton, vscForeground } from "../.."; import { IdeMessengerContext } from "../../../context/IdeMessenger"; import { isJetBrains } from "../../../util"; +import { setLocalStorage } from "../../../util/localStorage"; interface GitHubSignInButtonProps { onComplete: (token: string) => void; @@ -52,6 +53,7 @@ function GitHubSignInButton(props: GitHubSignInButtonProps) { await ideMessenger.request("setGitHubAuthToken", { token: jbGhAuthToken, }); + setLocalStorage("signedInToGh", true); props.onComplete(jbGhAuthToken); }} > @@ -66,6 +68,7 @@ function GitHubSignInButton(props: GitHubSignInButtonProps) { "getGitHubAuthToken", undefined, ); + setLocalStorage("signedInToGh", true); props.onComplete(token); }} className="grid grid-flow-col items-center gap-2" diff --git a/gui/src/pages/onboarding/apiKeyOnboarding.tsx b/gui/src/pages/onboarding/apiKeyOnboarding.tsx index 5aa0fc6c7..a086cdc87 100644 --- a/gui/src/pages/onboarding/apiKeyOnboarding.tsx +++ b/gui/src/pages/onboarding/apiKeyOnboarding.tsx @@ -3,6 +3,7 @@ import { useContext } from "react"; import { useNavigate } from "react-router-dom"; import QuickModelSetup from "../../components/modelSelection/quickSetup/QuickModelSetup"; import { IdeMessengerContext } from "../../context/IdeMessenger"; +import { getLocalStorage } from "../../util/localStorage"; function ApiKeyOnboarding() { const ideMessenger = useContext(IdeMessengerContext); @@ -23,7 +24,12 @@ function ApiKeyOnboarding() { { ideMessenger.post("showTutorial", undefined); - navigate("/apiKeyAutocompleteOnboarding"); + + if (getLocalStorage("signedInToGh") === true) { + navigate("/"); + } else { + navigate("/apiKeyAutocompleteOnboarding"); + } }} > diff --git a/gui/src/util/localStorage.ts b/gui/src/util/localStorage.ts index 0f6c29656..3a06b9a6a 100644 --- a/gui/src/util/localStorage.ts +++ b/gui/src/util/localStorage.ts @@ -11,6 +11,7 @@ type LocalStorageTypes = { inputHistory: JSONContent[]; extensionVersion: string; indexingState: IndexingProgressUpdate; + signedInToGh: boolean; }; export function getLocalStorage(