[Repo Assist] fix: read phpcbf.onsave per-document URI in onWillSaveTextDocument#68
Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
Draft
Conversation
In multi-root workspaces, different workspace folders can have different phpcbf.onsave values (scope: resource). The previous code checked phpcbf.onsave from the shared PHPCBF instance, which reflected the settings from the last loadSettings() call — not necessarily scoped to the document being saved. This caused a bug where a file in folder A (onsave: false) could trigger unwanted formatting if the PHPCBF instance last loaded settings from folder B (onsave: true), or vice versa. Fix: read phpcbf.onsave directly from the document-scoped configuration in the onWillSaveTextDocument handler, same way that editor.formatOnSave is already read on the next line. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.
🤖 This is an automated draft PR from Repo Assist, an AI assistant.
Summary
Fixes a multi-root workspace bug where
phpcbf.onsavewas read from the sharedPHPCBFinstance rather than scoped to the document being saved. This caused incorrect behaviour when different workspace folders had differentphpcbf.onsavevalues.Root Cause
phpcbf.onsaveis a resource-scoped setting ("scope": "resource"inpackage.json), meaning it can differ per workspace folder in a multi-root setup. However, theonWillSaveTextDocumenthandler was checkingphpcbf.onsave— a property on the shared instance that reflects whateverloadSettings()was last called with (the constructor, or anonDidChangeConfigurationevent, neither of which are per-document).Reproduction (multi-root workspace)
"phpcbf.onsave": false"phpcbf.onsave": truephpcbf.onsave = truein the instance)phpcbf.onsaveis stilltrueThe reverse is also true: save a file from folder B after activating a file from folder A, and formatting does not fire when it should.
Fix
Read
phpcbf.onsavedirectly fromworkspace.getConfiguration("phpcbf", event.document.uri)in the handler — identical to howeditor.formatOnSaveis already read on the very next line. This is the correct per-resource scoping pattern for VS Code extensions.Before / After