diff --git a/core/indexing/indexCodebase.ts b/core/indexing/indexCodebase.ts index 32c85f2b9..fe094711e 100644 --- a/core/indexing/indexCodebase.ts +++ b/core/indexing/indexCodebase.ts @@ -6,12 +6,27 @@ import { ChunkCodebaseIndex } from "./chunk/ChunkCodebaseIndex"; import { getComputeDeleteAddRemove } from "./refreshIndex"; import { CodebaseIndex, IndexTag } from "./types"; +export class PauseToken { + constructor(private _paused: boolean) {} + + set paused(value: boolean) { + this._paused = value; + } + + get paused(): boolean { + return this._paused; + } +} + export class CodebaseIndexer { configHandler: ConfigHandler; ide: IDE; - constructor(configHandler: ConfigHandler, ide: IDE) { + pauseToken: PauseToken; + + constructor(configHandler: ConfigHandler, ide: IDE, pauseToken: PauseToken) { this.configHandler = configHandler; this.ide = ide; + this.pauseToken = pauseToken; } private async getIndexesToBuild(): Promise { @@ -41,6 +56,12 @@ export class CodebaseIndexer { let completedDirs = 0; + yield { + progress: + 0, + desc: "Starting indexing...", + }; + for (let directory of workspaceDirs) { const stats = await this.ide.getStats(directory); const branch = await this.ide.getBranch(directory); @@ -64,6 +85,11 @@ export class CodebaseIndexer { results, markComplete )) { + // Handle pausing in this loop because it's the only one really taking time + while (this.pauseToken.paused) { + await new Promise((resolve) => setTimeout(resolve, 100)); + } + yield { progress: (completedDirs + diff --git a/core/web/webviewProtocol.ts b/core/web/webviewProtocol.ts index ed84460f3..248fe468f 100644 --- a/core/web/webviewProtocol.ts +++ b/core/web/webviewProtocol.ts @@ -61,6 +61,7 @@ export type WebviewProtocol = Protocol & ]; errorPopup: [{ message: string }, void]; + "index/setPaused": [boolean, void]; openUrl: [string, void]; applyToCurrentFile: [{ text: string }, void]; showTutorial: [undefined, void]; diff --git a/extensions/vscode/src/extension/vscodeExtension.ts b/extensions/vscode/src/extension/vscodeExtension.ts index 82a0355bb..51b369766 100644 --- a/extensions/vscode/src/extension/vscodeExtension.ts +++ b/extensions/vscode/src/extension/vscodeExtension.ts @@ -1,5 +1,5 @@ import { ConfigHandler } from "core/config/handler"; -import { CodebaseIndexer } from "core/indexing/indexCodebase"; +import { CodebaseIndexer, PauseToken } from "core/indexing/indexCodebase"; import { v4 as uuidv4 } from "uuid"; import * as vscode from "vscode"; import { registerAllCommands } from "../commands"; @@ -90,8 +90,21 @@ export class VsCodeExtension { ); this.webviewProtocol = this.sidebar.webviewProtocol; + // Indexing + pause token + const indexingPauseToken = new PauseToken( + context.globalState.get("continue.indexingPaused") === false + ); + this.webviewProtocol.on("index/setPaused", (msg) => { + context.globalState.update("continue.indexingPaused", msg.data); + indexingPauseToken.paused = msg.data; + }); + this.diffManager.webviewProtocol = this.webviewProtocol; - this.indexer = new CodebaseIndexer(this.configHandler, this.ide); + this.indexer = new CodebaseIndexer( + this.configHandler, + this.ide, + indexingPauseToken + ); // CodeLens registerAllCodeLensProviders( diff --git a/extensions/vscode/src/webviewProtocol.ts b/extensions/vscode/src/webviewProtocol.ts index cc8297694..6cdda8a72 100644 --- a/extensions/vscode/src/webviewProtocol.ts +++ b/extensions/vscode/src/webviewProtocol.ts @@ -30,7 +30,7 @@ export class VsCodeWebviewProtocol { return id; } - private on( + on( messageType: T, handler: ( message: Message diff --git a/gui/src/components/loaders/IndexingProgressBar.tsx b/gui/src/components/loaders/IndexingProgressBar.tsx index 29674e271..7d8b5528f 100644 --- a/gui/src/components/loaders/IndexingProgressBar.tsx +++ b/gui/src/components/loaders/IndexingProgressBar.tsx @@ -1,7 +1,8 @@ -import { useState } from "react"; +import { useEffect, useState } from "react"; import ReactDOM from "react-dom"; import styled from "styled-components"; import { StyledTooltip, lightGray, vscForeground } from ".."; +import { postToIde } from "../../util/ide"; const DIAMETER = 6; const CircleDiv = styled.div` @@ -65,6 +66,10 @@ const IndexingProgressBar = ({ const [expanded, setExpanded] = useState(true); const [hovered, setHovered] = useState(false); + useEffect(() => { + postToIde("index/setPaused", !expanded); + }, [expanded]); + return (
setExpanded((prev) => !prev)}