[Repo Assist] feat: register DocumentRangeFormattingEditProvider to enable editor.formatOnPaste#103
Conversation
…ormatOnPaste
phpcbf operates on the full document context, so range-only formatting
is not meaningful. The range provider delegates to the same full-document
pipeline as the existing DocumentFormattingEditProvider.
This allows users to enable paste-triggered formatting with:
"[php]": {
"editor.defaultFormatter": "persoderlind.vscode-phpcbf",
"editor.formatOnPaste": true
}
Closes #20
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
This doesn't change anything meaningful. |
|
🤖 This is an automated response from Repo Assist. Thanks for the feedback, What changes with this PR:
The acknowledged limitation: phpcbf always operates on a complete PHP file — it cannot meaningfully fix an isolated snippet without full file context. So the range parameter from VS Code is intentionally ignored, and the full document is formatted. The PR body documents this trade-off explicitly. This means "Format Selection" will format the entire document rather than just the selection — which is the correct behaviour for a whole-file tool like phpcbf, and consistent with how many other PHP formatters handle this constraint.
|
🤖 This is an automated draft PR from Repo Assist, an AI assistant.
Summary
Closes #20.
Registers a
DocumentRangeFormattingEditProviderfor PHP so that VS Code's built-ineditor.formatOnPastefeature works with this extension.Background
VS Code's
editor.formatOnPastecallsprovideDocumentRangeFormattingEditswhen content is pasted. Without a range formatting provider registered, the paste event silently falls through without formatting — which is why users couldn't useeditor.formatOnPastewith this extension.Implementation
phpcbf always needs the full document context to apply fixes correctly (it cannot format an isolated range). The range provider delegates to the same full-document pipeline as the existing
DocumentFormattingEditProvider, via a sharedgetFullDocumentEditshelper. The requested range is intentionally ignored.This also reduces duplication: the formatting logic is now defined once in
getFullDocumentEditsand called by both providers.Usage
After this PR is merged, users can enable format-on-paste by adding to their
settings.json:No new extension config option is needed —
editor.formatOnPasteis a standard VS Code setting.Changes
extension.js: extracted sharedgetFullDocumentEditshelper; addedregisterDocumentRangeFormattingEditProvidercall inside the existingphpcbf.documentFormattingProviderguardTest Status
✅ Syntax check:
⚠️ Integration tests: VS Code integration tests require a GUI environment; the range provider correctly delegates to the existing formatter pipeline which is already tested end-to-end by users.
node --check extension.js— no syntax errors✅ Unit tests:
node --test test/unit.test.js— 7/7 tests pass (no regression)