[Repo Assist] fix: replace deprecated async fs.exists with fs.existsSync in addRootPath#51
Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
Conversation
…Path The previous code used fs.exists() (deprecated async callback) to check whether the resolved executable path exists before applying it. Because the callback ran asynchronously, loadSettings() returned before the path was updated. On the first save after a VS Code restart, getArgs() was called with the still-relative executablePath, causing spawn to fail. Fix: use fs.existsSync() so the path check and update are synchronous and complete before loadSettings() returns. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Mar 9, 2026
github-actions bot
added a commit
that referenced
this pull request
Mar 9, 2026
Documents the bug fixes and improvements from the open Repo Assist PRs: - Fix formatter hang on exit code 0 (PR #49, closes #39) - Fix phpcbf.enable=false bypass (PR #56) - Fix temp file leak on process error (PR #58) - Fix onWillSaveTextDocument save timeout (PR #53, closes #35) - Fix deprecated fs.exists (PR #51, closes #36) - Fix undefined showErrorMessage on unknown exit code (PR #61) - Add VS Code output channel for debug/error display (PR #50) - Refactor getArgs standard variable (PR #60) - Fix eslintrc and no-case-declarations lint issues Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
github-actions bot
added a commit
that referenced
this pull request
Mar 10, 2026
- Replace deprecated async fs.exists() with synchronous fs.existsSync() in addRootPath(), eliminating the race condition where executablePath would be updated after cp.spawn() had already used the old value. Supersedes PR #51. - Use path.join() for temp file construction instead of string concat with a hard-coded slash, fixing the double-slash on macOS when os.tmpdir() returns a path ending in '/'. Supersedes PR #49 (partial). - Remove broken phpcbfError flag pattern. The flag was evaluated synchronously before any exit event fired, so the conditional stdout listener was never attached for exit code 3. Replace with an unconditional stdoutOutput accumulator used inside the exit handler. Supersedes PR #49 (partial). - Reject the promise for exit code 0 (nothing to fix) so VS Code's formatter API is notified immediately instead of hanging until restart. Closes #39. Supersedes PR #48, PR #49. - Show a meaningful error message for exit code 3 using buffered stdout (or a fallback string), then reject so the spinner clears. Previously the error message was silently swallowed. - Clean up temp file in the error handler (exec.on('error')) to prevent orphaned files when the executable is not found. Supersedes PR #58. - Add block scopes around case 1/2 and default to silence no-case-declarations lint errors without disabling the rule. - Remove the unreachable 3: entry from the msgs lookup in the default case, and fall back gracefully for unknown exit codes instead of calling window.showErrorMessage(undefined). Supersedes PR #61. - Use a local const for the resolved standard in getArgs() instead of writing back to this.standard, removing the accidental side effect that could clobber the instance state mid-format. Supersedes PR #60. - Guard onDidChangeConfiguration reload with event.affectsConfiguration('phpcbf') so unrelated setting changes (e.g. font, theme) do not trigger unnecessary reloads. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Mar 10, 2026
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 PR from Repo Assist, an AI assistant.
Summary
Replaces the deprecated async
fs.exists()callback with the synchronousfs.existsSync()inaddRootPath().Root Cause
addRootPath()is called fromloadSettings()to resolve relativeexecutablePathvalues (e.g../vendor/bin/phpcbf) to absolute paths. The old code usedfs.exists(path, callback)— a deprecated Node.js API that runs the existence check asynchronously:When
loadSettings()returns,this.executablePathis still the original relative path.format()immediately callsgetArgs()with that unresolved path, socp.spawn()receives./vendor/bin/phpcbfinstead of the absolute path, causing a spawn failure.This is the race condition behind issue #36: "after restart vscode it can't find the exePath anymore." The extension works after the second save (because the async callback has already fired by then), but fails on the first save after each restart.
Fix
fs.existsSync()is synchronous, stable, and the idiomatic replacement forfs.exists()which has been deprecated since Node.js v4.Files Changed
extension.jsfs.exists(path, callback)withif (fs.existsSync(path))inaddRootPath()Test Status
This extension requires a live VS Code instance. No CI is configured for this repository.
Manual test steps:
phpcbf.executablePathto a relative path (e.g../vendor/bin/phpcbf)Closes #36