✨ pause indexing
This commit is contained in:
parent
bfbc3b8a7f
commit
818928dff7
5 changed files with 50 additions and 5 deletions
|
|
@ -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<CodebaseIndex[]> {
|
||||
|
|
@ -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 +
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -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<boolean>("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(
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ export class VsCodeWebviewProtocol {
|
|||
return id;
|
||||
}
|
||||
|
||||
private on<T extends keyof WebviewProtocol>(
|
||||
on<T extends keyof WebviewProtocol>(
|
||||
messageType: T,
|
||||
handler: (
|
||||
message: Message<WebviewProtocol[T][0]>
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<div
|
||||
onClick={() => setExpanded((prev) => !prev)}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue