Skip to content

Commit

Permalink
Fix sidebar indexing status timing-related bugs (#1368)
Browse files Browse the repository at this point in the history
* readd overwritten commit

* Remove duplicated code

* Fix status load in and failed state update

* Late sidebar open bugs fixed

* Change ideMessenger post parameters

* debug pause

* Don't use global, fix table creation bug

* Creating new branch for config-related issues here

* cleanup
  • Loading branch information
justinmilner1 authored May 28, 2024
1 parent 759ba12 commit b70552a
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 14 deletions.
11 changes: 11 additions & 0 deletions core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ 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<ToCoreProtocol, FromCoreProtocol>
configHandler: ConfigHandler;
codebaseIndexerPromise: Promise<CodebaseIndexer>;
completionProvider: CompletionProvider;
continueServerClientPromise: Promise<ContinueServerClient>;
indexingState: IndexingProgressUpdate

private abortedMessageIds: Set<string> = new Set();

Expand Down Expand Up @@ -59,6 +61,7 @@ export class Core {
private readonly ide: IDE,
private readonly onWrite: (text: string) => Promise<void> = async () => {},
) {
this.indexingState = { status:"loading", desc: 'loading', progress: 0 }
const ideSettingsPromise = messenger.request("getIdeSettings", undefined);
this.configHandler = new ConfigHandler(
this.ide,
Expand Down Expand Up @@ -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;
Expand All @@ -533,6 +543,7 @@ export class Core {
this.indexingCancellationController.signal,
)) {
this.messenger.request("indexProgress", update);
this.indexingState = update
}
}
}
2 changes: 1 addition & 1 deletion core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion core/indexing/LanceDbIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ export class LanceDbIndex implements CodebaseIndex {

// Compute
let table: Table<number[]> | undefined = undefined;
let needToCreateTable = true;
const existingTables = await db.tableNames();
let needToCreateTable = !existingTables.includes(tableName);

const addComputedLanceDbRows = async (
pathAndCacheKey: PathAndCacheKey,
Expand Down
16 changes: 11 additions & 5 deletions core/indexing/indexCodebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,24 @@ 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;
} else {
yield {
progress: 0,
desc: "Starting indexing",
status: "starting",
status: "loading",
};
}

Expand All @@ -88,7 +88,7 @@ export class CodebaseIndexer {
yield {
progress: 0,
desc: "Starting indexing...",
status: "starting",
status: "loading",
};

for (const directory of workspaceDirs) {
Expand Down Expand Up @@ -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
}
}

Expand Down
1 change: 1 addition & 0 deletions core/protocol/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export type ToCoreFromIdeOrWebviewProtocol = {
];
"index/setPaused": [boolean, void];
"index/forceReIndex": [undefined | string, void];
"index/indexingProgressBarInitialized": [undefined, void];
completeOnboarding: [
{
mode:
Expand Down
1 change: 1 addition & 0 deletions core/protocol/passThrough.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] =
"stats/getTokensPerModel",
"index/setPaused",
"index/forceReIndex",
"index/indexingProgressBarInitialized",
"completeOnboarding",
"addAutocompleteModel",
];
Expand Down
1 change: 1 addition & 0 deletions core/util/GlobalContext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from "node:fs";
import { getGlobalContextFilePath } from "./paths";
import { IndexingProgressUpdate } from "..";

export type GlobalContextType = {
indexingPaused: boolean;
Expand Down
6 changes: 3 additions & 3 deletions gui/src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,10 @@ const Layout = () => {
}
}, [location]);

const [indexingState, setIndexingState] = useState<IndexingProgressUpdate>({
desc: "Indexing disabled",
const [indexingState, setIndexingState] = useState<IndexingProgressUpdate>({
desc: "Loading indexing config",
progress: 0.0,
status: "disabled",
status: "loading",
});

return (
Expand Down
26 changes: 22 additions & 4 deletions gui/src/components/loaders/IndexingProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
<>
<CircleDiv
data-tooltip-id="indexingNotLoaded_dot"
Expand All @@ -96,7 +114,7 @@ const IndexingProgressBar = ({ indexingState }: ProgressBarProps) => {
{tooltipPortalDiv &&
ReactDOM.createPortal(
<StyledTooltip id="indexingNotLoaded_dot" place="top">
Codebase indexing is starting up.
Continue is initializing
</StyledTooltip>,
tooltipPortalDiv,
)}
Expand Down

0 comments on commit b70552a

Please sign in to comment.