[Repo Assist] fix: use correct waitUntil API in onWillSaveTextDocument#131
Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
Draft
Conversation
Replace commands.executeCommand('editor.action.formatDocument') with a
direct call to phpcbf.format(event.document) returning TextEdit[].
Two bugs in the old approach:
1. editor.action.formatDocument always formats the *active* text editor,
not event.document. When a background PHP file is saved (e.g. via
auto-save or a multi-root workspace scenario), the wrong document
would be formatted.
2. commands.executeCommand returns Thenable<void>, while waitUntil
accepts Thenable<TextEdit[]> for atomic-edit application. Passing
Thenable<void> means VS Code never applies edits through the save
pipeline — the format runs as a side-effect that may race with the
save rather than being part of it.
The fix calls phpcbf.format(event.document) directly, maps the result
to a TextEdit array, and passes that to event.waitUntil — matching the
documented VS Code API contract.
Also reads phpcbf.onsave scoped to event.document.uri so per-folder
settings in multi-root workspaces are correctly resolved.
Relates to #35 (onWillSaveTextDocument timeout errors).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Apr 4, 2026
Open
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 two bugs in the
onWillSaveTextDocumenthandler by replacingcommands.executeCommand("editor.action.formatDocument")with a direct call tophpcbf.format(event.document)that returnsTextEdit[].Problem
The old code:
Has two distinct bugs:
Bug 1 — Formats the wrong document
editor.action.formatDocumentalways targets the active text editor, notevent.document. If a background PHP file is saved (e.g. via auto-save, or in a multi-root workspace where a non-focused document triggers a save), the active editor's document gets formatted instead of the document actually being saved.Bug 2 — Wrong return type for
waitUntilcommands.executeCommandreturnsThenable(void), butevent.waitUntilacceptsThenable(TextEdit[])for the atomic-edit form. PassingThenable(void)means VS Code never applies edits through its internal save pipeline. Instead, the format runs as an untracked side-effect that may race with the save operation rather than being properly sequenced as part of it.The [VS Code API docs]((code.visualstudio.com/redacted) state:
Fix
Call
phpcbf.format(event.document)directly, convert the result to aTextEditcovering the full document, and pass that towaitUntil. Errors are caught and converted to an emptyTextEdit[](no change), preventing VS Code from blocking the save on a formatter error.Also reads
phpcbf.onsavescoped toevent.document.uriso per-folder settings in multi-root workspaces are correctly resolved (same fix as in PR #106).Relates To
onWillSaveTextDocument-listener error: timeout)Test Status
All 7 unit tests pass (
node --test test/unit.test.js). The full VS Code integration test harness requires a display and cannot run in CI.Manual verification:
phpcbf.onsave: trueandeditor.formatOnSave: falsein a PHP workspaceOverlap note: This PR also includes the per-document
onsavereading that PR #106 includes. If #106 merges first, only thewaitUntilfix would need to be retained from this PR.