fix: stop multi-root/huge-workspace hang and crash (#7)#8
Merged
Conversation
Opening the panel previously scanned every workspace root recursively, shipped the whole tree in one postMessage, and rendered every node regardless of collapse state — OOMing the host/webview on large or multi-root workspaces. Backend (extension): - Lazy APIs: getWorkspaceRoots (shallow), getDirectoryChildren, listFilesUnderUri; getWorkspaceFileTree kept (capped) for legacy/tests - Default heavy-dir excludes (node_modules, dist, build, .next, ...) - Async gitignore I/O via loadIgnoreRulesForRoot - Scan caps (depth/nodes/list) + AbortSignal + coalesced getFileTree - copyContext uses generateFileMapFromSelections (no full-tree cache) Webview: - Collapse-gated render; only expanded folders render children - Lazy expand fetches children via getDirectoryChildren and merges them - Select-all uses extension listFilesUnderUri; truncation banner - Iterative getAllDescendantPaths Fixes found while validating: - buildTreeIndex crashed on shallow (unloaded) folders whose subItems is undefined — guard with `subItems ?? []` - Seeded-expanded roots never fetched children on first render/refresh — auto-load expanded-but-unloaded roots (guarded by loadingFolderUris) Tests: - Backend file-system.test.ts: excludes/gitignore/abort/shallow roots (workspace-scoped cases self-skip if workspaceFolders can't be stubbed) - Webview: shallow-root auto-load, no double-request, no auto-load of already-loaded roots; buildTreeIndex shallow-folder coverage Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7.
Problem
Opening the panel scanned every workspace root recursively, sent the whole tree in one
postMessage, and rendered every node regardless of collapse state — OOM on large/multi-root workspaces.Changes
getWorkspaceRoots(shallow) +getDirectoryChildrenon expand; children merged into tree statenode_modules,dist,build,.next, ...) + async gitignore I/OAbortSignal+ 30s timeout + coalescedgetFileTreelistFilesUnderUri;copyContextviagenerateFileMapFromSelections(no full-tree cache)getAllDescendantPaths; truncation bannerBugs fixed (not caught by old tests — they only used a populated mock tree)
buildTreeIndexthrew on shallow folders (subItemsundefined) → guarded withsubItems ?? []loadingFolderUris)Tests
file-system.test.ts: excludes/gitignore/abort/shallow roots (workspace cases self-skip ifworkspaceFolderscan't be stubbed)buildTreeIndexshallow coverageVerified
check-types,tsc -p . --outDir out,biome check srcclean;pnpm -C src/webview-ui test --run→ 119 passed.Not run here (confirm in CI/local)
pnpm test(electron host); manual multi-root.code-workspacerepro.Known limitations
none/partialuntil expanded (counts reflect loaded nodes only)