Rework for proper initialization on start up
This commit is contained in:
parent
0266947a52
commit
de9f6ee315
5 changed files with 98 additions and 33 deletions
|
|
@ -71,7 +71,6 @@ export class CodebaseIndexer {
|
|||
}
|
||||
|
||||
//Test to see if embeddings provider is configured properly
|
||||
// let indexingFailed = false;
|
||||
try {
|
||||
await config.embeddingsProvider.embed(['sample text']);
|
||||
} catch (error) {
|
||||
|
|
@ -150,7 +149,7 @@ export class CodebaseIndexer {
|
|||
console.warn(
|
||||
`Error updating the ${codebaseIndex.artifactId} index: ${e}`,
|
||||
);
|
||||
yield {progress: 1, desc: "error updating index", indexingFailed: true}
|
||||
yield {progress: 1, desc: "error updating index"}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,8 @@ export type WebviewProtocol = Protocol &
|
|||
errorPopup: [{ message: string }, void];
|
||||
"index/setPaused": [boolean, void];
|
||||
"index/forceReIndex": [undefined, void];
|
||||
"index/setIndexingFailed": [{message: string, failed: boolean}, void];
|
||||
"index/setIndexingFailed": [{failed: boolean}, void];
|
||||
"index/indexingProgressBarInitialized": [{ready: boolean}, void]
|
||||
openUrl: [string, void];
|
||||
applyToCurrentFile: [{ text: string }, void];
|
||||
showTutorial: [undefined, void];
|
||||
|
|
@ -129,7 +130,8 @@ export type ReverseWebviewProtocol = {
|
|||
openSettings: [undefined, void];
|
||||
viewHistory: [undefined, void];
|
||||
indexProgress: [{ progress: number; desc: string }, void];
|
||||
setIndexingFailed: [{message: string, failed: boolean}, void];
|
||||
setIndexingFailed: [{failed: boolean}, void];
|
||||
indexingProgressBarInitialized: [{ready: boolean}, void]
|
||||
newSession: [undefined, void];
|
||||
refreshSubmenuItems: [undefined, void];
|
||||
setTheme: [{ theme: any }, void];
|
||||
|
|
|
|||
|
|
@ -112,14 +112,52 @@ export class VsCodeExtension {
|
|||
this.webviewProtocol.on("index/forceReIndex", (msg) => {
|
||||
this.ide
|
||||
.getWorkspaceDirs()
|
||||
.then((dirs) => this.refreshCodebaseIndex(dirs));
|
||||
//ToDo: Maybe set indexingFailed to false here - no i dont think so
|
||||
.then((dirs) => this.refreshCodebaseIndex(dirs, context));
|
||||
context.globalState.update("continue.indexingFailed", false)
|
||||
console.log("modified global state to false (in forcereindex)")
|
||||
});
|
||||
// let indexingProgressBar: boolean = false
|
||||
this.webviewProtocol.on("index/setIndexingFailed", (msg) => {
|
||||
console.log("updating indexFailed globalState")
|
||||
context.globalState.update("continue.indexingFailed", msg.data); //Todo: not sure if this is needed
|
||||
console.log("forwarding setIndexingFailed to webviewProtocol")
|
||||
|
||||
//if the sidebar has not been opened, this request will not succeed
|
||||
this.webviewProtocol?.request("setIndexingFailed", msg.data);
|
||||
|
||||
//Set the global state so that when the sidebar is opened, it can read the state
|
||||
context.globalState.update("continue.indexingFailed", msg.data)
|
||||
|
||||
|
||||
// If the indexing progress bar has been initialized do the update,
|
||||
// otherwise, put it in a queue, which will execute when the bar is initialized
|
||||
// if (indexingProgressBar) {
|
||||
// console.log("not adding to queue, doing update")
|
||||
// context.globalState.update("continue.indexingFailed", msg.data);
|
||||
// } else {
|
||||
// console.log("adding to message queue")
|
||||
// messageQueue.push(msg.data)
|
||||
// }
|
||||
});
|
||||
// let messageQueue: {failed:boolean}[] = [];
|
||||
this.webviewProtocol.on("index/indexingProgressBarInitialized", (msg) => {
|
||||
console.log("from vscode extension, forwarding setIndexingFailed from index bar initialized")
|
||||
|
||||
if (context.globalState.get("continue.indexingFailed")){
|
||||
console.log("global state was true: ", context.globalState.get("continue.indexingFailed"))
|
||||
this.webviewProtocol?.request("setIndexingFailed", {failed: true});
|
||||
} else {
|
||||
console.log("global state was false: ", context.globalState.get("continue.indexingFailed"))
|
||||
this.webviewProtocol?.request("setIndexingFailed", {failed: false});
|
||||
}
|
||||
|
||||
|
||||
//console.log("forwarding indexProgressBarInitialized to webviewProtocol")
|
||||
//this.webviewProtocol?.request("indexingProgressBarInitialized", {ready:true});
|
||||
// console.log("webview, initializing progress bar. messagequeu len: ", messageQueue.length)
|
||||
// indexingProgressBar = true
|
||||
// for (let i = 0; i < messageQueue.length; i++) {
|
||||
// context.globalState.update("continue.indexingFailed", messageQueue[i])
|
||||
// }
|
||||
// messageQueue = []
|
||||
});
|
||||
|
||||
this.diffManager.webviewProtocol = this.webviewProtocol;
|
||||
|
|
@ -196,7 +234,7 @@ export class VsCodeExtension {
|
|||
registerDebugTracker(this.webviewProtocol, this.ide);
|
||||
|
||||
// Indexing
|
||||
this.ide.getWorkspaceDirs().then((dirs) => this.refreshCodebaseIndex(dirs));
|
||||
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
|
||||
|
|
@ -238,7 +276,7 @@ export class VsCodeExtension {
|
|||
currentBranch !== this.PREVIOUS_BRANCH_FOR_WORKSPACE_DIR[dir]
|
||||
) {
|
||||
// Trigger refresh of index only in this directory
|
||||
this.refreshCodebaseIndex([dir]);
|
||||
this.refreshCodebaseIndex([dir], context);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -274,17 +312,16 @@ export class VsCodeExtension {
|
|||
private PREVIOUS_BRANCH_FOR_WORKSPACE_DIR: { [dir: string]: string } = {};
|
||||
private indexingCancellationController: AbortController | undefined;
|
||||
|
||||
private async refreshCodebaseIndex(dirs: string[]) {
|
||||
//ToDo:Maybe a try catch block here which calls handleIndexingFailure?
|
||||
private async refreshCodebaseIndex(dirs: string[], context: vscode.ExtensionContext) {
|
||||
console.log("setting to false from refreshcodebase")
|
||||
this.webviewProtocol?.request("setIndexingFailed", {
|
||||
message: "false",
|
||||
failed: false
|
||||
});
|
||||
this.webviewProtocol?.request("setIndexingFailed", {failed:false});
|
||||
context.globalState.update("continue.indexingFailed", false)
|
||||
|
||||
if (this.indexingCancellationController) {
|
||||
this.indexingCancellationController.abort();
|
||||
}
|
||||
this.indexingCancellationController = new AbortController();
|
||||
let err = undefined
|
||||
for await (const update of this.indexer.refresh(
|
||||
dirs,
|
||||
this.indexingCancellationController.signal,
|
||||
|
|
@ -295,14 +332,20 @@ export class VsCodeExtension {
|
|||
// message: 'Failed to index codebase',
|
||||
// });
|
||||
console.log("setting to true from refreshcodebase")
|
||||
this.webviewProtocol?.request("setIndexingFailed", {
|
||||
message: update.desc,
|
||||
failed: true
|
||||
});
|
||||
this.webviewProtocol?.request("setIndexingFailed", {failed: true});
|
||||
context.globalState.update("continue.indexingFailed", true)
|
||||
err = update.desc
|
||||
} else {
|
||||
this.webviewProtocol.request("indexProgress", update);
|
||||
}
|
||||
}
|
||||
|
||||
if (err) {
|
||||
console.log("Codebase Indexing Failed: ", err)
|
||||
} else {
|
||||
console.log("Codebase Indexing Complete")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//ToDO:
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ import TextDialog from "./dialogs";
|
|||
import IndexingProgressBar from "./loaders/IndexingProgressBar";
|
||||
import ProgressBar from "./loaders/ProgressBar";
|
||||
import ModelSelect from "./modelSelection/ModelSelect";
|
||||
import * as vscode from "../../../extensions/vscode";
|
||||
|
||||
|
||||
// #region Styled Components
|
||||
const FOOTER_HEIGHT = "1.8em";
|
||||
|
|
@ -167,11 +169,32 @@ const Layout = () => {
|
|||
setIndexingTask(data.desc);
|
||||
});
|
||||
|
||||
// let indexingProgressBarInitialized: boolean = false
|
||||
// let messageQueue: {failed:boolean}[] = [];
|
||||
// useWebviewListener("indexingProgressBarInitialized", async (data) => {
|
||||
// indexingProgressBarInitialized = true
|
||||
// console.log("webview, initializing progress bar. message queue len: ", messageQueue.length)
|
||||
|
||||
// for (let i = 0; i < messageQueue.length; i++) {
|
||||
// setIndexingFailed(messageQueue[i].failed)
|
||||
// }
|
||||
// messageQueue = []
|
||||
// });
|
||||
|
||||
//ToDO: does this update
|
||||
useWebviewListener("setIndexingFailed", async (data) => {
|
||||
console.log("setting indexing failed to (i think): ", data.failed)
|
||||
setIndexingFailed(data.failed);
|
||||
setIndexingFailed(data.failed)
|
||||
|
||||
// // Check if bar has been initialized
|
||||
// if (indexingProgressBarInitialized) {
|
||||
// console.log("no pushing to queue")
|
||||
// setIndexingFailed(data.failed)
|
||||
// } else {
|
||||
// console.log("pushing to queue")
|
||||
// messageQueue.push(data)
|
||||
// }
|
||||
console.log("From layout. setting indexing failed to : ", data.failed)
|
||||
//postToIde("index/setIndexingFailed", {failed: data.failed})
|
||||
//setIndexingFailed(data.failed); //may not needs this if switch to global
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -194,7 +217,7 @@ const Layout = () => {
|
|||
|
||||
const [indexingProgress, setIndexingProgress] = useState(1);
|
||||
const [indexingTask, setIndexingTask] = useState("Indexing Codebase");
|
||||
const [indexingFailed, setIndexingFailed] = useState(false); //ToDO: is this default? Or what it changes it to?
|
||||
const [indexingFailed, setIndexingFailed] = useState(false);
|
||||
|
||||
return (
|
||||
<LayoutTopDiv>
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ const IndexingProgressBar = ({
|
|||
completed,
|
||||
total,
|
||||
currentlyIndexing,
|
||||
indexingFailed,
|
||||
indexingFailed = false
|
||||
}: ProgressBarProps) => {
|
||||
const fillPercentage = Math.min(100, Math.max(0, (completed / total) * 100));
|
||||
|
||||
|
|
@ -68,24 +68,22 @@ const IndexingProgressBar = ({
|
|||
const [expanded, setExpanded] = useState(true);
|
||||
const [hovered, setHovered] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
console.log("posting initialization from progress bar")
|
||||
postToIde("index/indexingProgressBarInitialized", {ready:true})
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
postToIde("index/setPaused", !expanded);
|
||||
}, [expanded]);
|
||||
|
||||
// useEffect(() => {
|
||||
// setFailed(true);
|
||||
// console.log("In progress bar use effect: ", indexingFailed)
|
||||
// }, [indexingFailed]);
|
||||
|
||||
return (
|
||||
<div
|
||||
onClick={() => {
|
||||
console.log(completed, " | ", total, " | ", expanded)
|
||||
if (completed < total) {
|
||||
setExpanded((prev) => !prev);
|
||||
} else {
|
||||
// console.log("indexingFailed was: ", indexingFailed)
|
||||
indexingFailed = false
|
||||
// console.log("setting failed to False")
|
||||
postToIde("index/forceReIndex", undefined);
|
||||
}
|
||||
}}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue