feat: Fix progress bar hanging and improve UI responsiveness during indexing

Adds strategic yield points and direct stdout writes to prevent progress animation from freezing when the main thread is blocked by synchronous operations. Introduces 'finalizing' phase to smooth transition between parsing and resolving steps, ensuring progress reaches 100% completion.
This commit is contained in:
Colby McHenry
2026-04-06 09:50:30 -05:00
parent b768a9aa18
commit 9a2d3d9a13
5 changed files with 55 additions and 9 deletions
+13 -3
View File
@@ -390,6 +390,16 @@ export class CodeGraph {
// Resolve references to create call/import/extends edges
if (result.success && result.filesIndexed > 0) {
// Signal transition so progress bar doesn't hang at "Parsing 100%"
options.onProgress?.({
phase: 'finalizing',
current: 0,
total: 0,
});
// Yield so shimmer worker can flush the phase transition to stdout
await new Promise(resolve => setImmediate(resolve));
// Get count without loading all refs into memory
const unresolvedCount = this.queries.getUnresolvedReferencesCount();
@@ -399,7 +409,7 @@ export class CodeGraph {
total: unresolvedCount,
});
this.resolveReferencesBatched((current, total) => {
await this.resolveReferencesBatched((current, total) => {
options.onProgress?.({
phase: 'resolving',
current,
@@ -479,7 +489,7 @@ export class CodeGraph {
total: unresolvedCount,
});
this.resolveReferencesBatched((current, total) => {
await this.resolveReferencesBatched((current, total) => {
options.onProgress?.({
phase: 'resolving',
current,
@@ -540,7 +550,7 @@ export class CodeGraph {
* Resolve references in batches to keep memory bounded on large codebases.
* Processes chunks of unresolved refs, persisting results after each batch.
*/
resolveReferencesBatched(onProgress?: (current: number, total: number) => void): ResolutionResult {
async resolveReferencesBatched(onProgress?: (current: number, total: number) => void): Promise<ResolutionResult> {
return this.resolver.resolveAndPersistBatched(onProgress);
}