Skip to content

[Repo Assist] feat: register DocumentRangeFormattingEditProvider to enable editor.formatOnPaste#103

Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/feat-range-formatting-2026-03-22-2958c347b01ee90a
Draft

[Repo Assist] feat: register DocumentRangeFormattingEditProvider to enable editor.formatOnPaste#103
github-actions[bot] wants to merge 1 commit intomasterfrom
repo-assist/feat-range-formatting-2026-03-22-2958c347b01ee90a

Conversation

@github-actions
Copy link
Contributor

🤖 This is an automated draft PR from Repo Assist, an AI assistant.

Summary

Closes #20.

Registers a DocumentRangeFormattingEditProvider for PHP so that VS Code's built-in editor.formatOnPaste feature works with this extension.

Background

VS Code's editor.formatOnPaste calls provideDocumentRangeFormattingEdits when content is pasted. Without a range formatting provider registered, the paste event silently falls through without formatting — which is why users couldn't use editor.formatOnPaste with 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 shared getFullDocumentEdits helper. The requested range is intentionally ignored.

This also reduces duplication: the formatting logic is now defined once in getFullDocumentEdits and called by both providers.

Usage

After this PR is merged, users can enable format-on-paste by adding to their settings.json:

"[php]": {
  "editor.defaultFormatter": "persoderlind.vscode-phpcbf",
  "editor.formatOnPaste": true
}

No new extension config option is needed — editor.formatOnPaste is a standard VS Code setting.

Changes

  • extension.js: extracted shared getFullDocumentEdits helper; added registerDocumentRangeFormattingEditProvider call inside the existing phpcbf.documentFormattingProvider guard

Test Status

Syntax check: node --check extension.js — no syntax errors
Unit tests: node --test test/unit.test.js — 7/7 tests pass (no regression)
⚠️ 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.

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@346204513ecfa08b81566450d7d599556807389f

…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>
@garrettw
Copy link

This doesn't change anything meaningful.

@github-actions
Copy link
Contributor Author

🤖 This is an automated response from Repo Assist.

Thanks for the feedback, @garrettw! Let me clarify what this PR actually enables.

What changes with this PR:

  1. editor.formatOnPaste (closes phpcbf.onpaste option #20): Before this PR, pasting code into a PHP file with "editor.formatOnPaste": true silently does nothing — VS Code calls provideDocumentRangeFormattingEdits for paste events, and this extension didn't register that provider. After this PR, pasting triggers formatting.

  2. "Format Selection" (also addresses Format selection on context menu #32): The "Format Selection" context menu item and ⌘K ⌘F / Ctrl+K Ctrl+F shortcut also require a DocumentRangeFormattingEditProvider. Without this registration, both are greyed out / unavailable for PHP files with this extension.

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.

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@346204513ecfa08b81566450d7d599556807389f

@github-actions github-actions bot mentioned this pull request Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

phpcbf.onpaste option

1 participant