[Repo Assist] fix: scope addRootPath to document's workspace folder in multi-root workspaces#134
Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
Conversation
…orkspaces When a user has a multi-root workspace with per-folder phpcbf settings, addRootPath() was iterating over ALL workspace folders to resolve a relative executablePath. If multiple folders contained an executable at the same relative path, the last one iterated would win — regardless of which document was actually being formatted. Fix: accept an optional configUri parameter and, when provided, resolve the relative path against that document's workspace folder only. This ensures folder A's document always uses folder A's resolved executable, not folder B's. Also replace the deprecated asynchronous fs.exists() callback with the synchronous fs.existsSync(), eliminating the async race condition where format() could be called before the callback had set executablePath. Relates to: #36 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
66 tasks
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.
Problem
In a multi-root workspace where two or more folders each have
phpcbf.executablePathset to a relative path (e.g../vendor/bin/phpcbf), theaddRootPath()method was iterating over all workspace folders. If the same relative executable existed in multiple folders, the last folder in the iteration would win — regardless of which document was being formatted.For example, formatting a file from Folder A could end up using Folder B's resolved phpcbf executable if both folders had
./vendor/bin/phpcbf.This is a correctness bug in multi-root workspace setups with per-folder
executablePathconfiguration.Fix
Pass
configUritoaddRootPath()— when formatting a document, its URI is now threaded through toaddRootPath(). The method usesworkspace.getWorkspaceFolder(configUri)to find exactly the right folder and only checks that folder's executable path.Replace
fs.exists()withfs.existsSync()— the deprecated asyncfs.exists()callback was a separate race condition:loadSettings()could return before the callback fired, leavingexecutablePathas the unresolved relative path on the first format call after startup (see issue executablePath broken #36).fs.existsSync()resolves this synchronously.The fallback (when no
configUriis available, e.g. at activation time) is unchanged — it still iterates workspace folders.Root cause
Test Status
Unit tests: 7/7 passing (
npm run test:unit)No integration test environment is available in this CI context (requires VS Code host). The change is backwards-compatible: single-root workspaces and the activation-time fallback are unaffected.
Related
fs.exists→fs.existsSyncfix)fs.existsSyncfix (PR [Repo Assist] fix: consolidate critical bug fixes (pre-v0.0.10) #106 also fixes this and many other things; this PR is a focused standalone fix for the scoping issue)