[Repo Assist] perf: replace blocking fs.writeFileSync/readFileSync with async I/O in format()#110
Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
Conversation
…n format() Synchronous file operations in the extension host block VS Code's entire JavaScript thread while writing/reading PHP source files to/from the OS temp directory. For large PHP files this causes a visible pause in the UI. Changes: - fs.writeFileSync → fs.writeFile (async): temp file is written inside the Promise executor, so the extension host thread is freed immediately after spawning the write. - fs.readFileSync → fs.readFile (async): fixed-file read on exit codes 1/2 is now async; unlink is called inside the readFile callback so the temp file is cleaned up after the async read completes. - Removed the phpcbfError flag + deferred stdout-listener pattern, which was effectively dead code (the synchronous if-check always saw false). Code 3 now calls window.showErrorMessage directly in the exit handler, matching the documented intent. - Removed leftover 'console.log(code)' comment in close handler. All 7 unit tests pass (npm run test:unit). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Mar 27, 2026
Draft
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.
🤖 This is an automated draft PR from Repo Assist, an AI assistant.
Summary
Replaces the two synchronous file-I/O calls in
format()with async equivalents, freeing the VS Code extension host thread while PHP source files are being written to / read from the OS temp directory.Root cause
format()usedfs.writeFileSyncto write the document's text to a temp file before spawningphpcbf, andfs.readFileSyncto read the fixed text back on exit codes 1 or 2. Both calls block the entire extension host JavaScript thread. For large PHP files (or on slow storage such as a network drive or a Docker container) this manifests as a perceptible UI freeze.Changes
fs.writeFileSync(fileName, text)(sync, blocking)fs.writeFile(fileName, text, cb)(async, non-blocking)fs.readFileSync(fileName, "utf-8")(sync, blocking)fs.readFile(fileName, "utf-8", cb)(async, non-blocking)The entire
format()body is now wrapped in the Promise executor so the spawn and all event-handler setup happen inside thewriteFilecallback, once the temp file is ready.Incidental fixes
phpcbfError/ deferred stdout-listener dead code removed: The original code setphpcbfError = trueinside theexitcallback, then checked the flag synchronously after constructing the Promise — by which point the flag was alwaysfalse. The stdout listener for exit code 3 was therefore never attached. Replaced with a directwindow.showErrorMessagecall in the exit handler.constin place ofletwhere applicable; removed a stale// console.log(code)comment.Trade-offs
Test Status
npm run test:unit(7 findFiles unit tests)(The integration test suite requires a full VS Code environment and cannot run in CI for this project.)
Closes: N/A (performance improvement, no associated issue)