feat: Add textDocument/formatting support via phpcbf#54
feat: Add textDocument/formatting support via phpcbf#54mikebronner merged 1 commit intoGeneaLabs:mainfrom
Conversation
|
@mikebronner for your review. |
|
@s3rgiosan Thanks for submitting this PR! I wanted to check though: did you know that this plugin already supported who-document fixes via Zed's quick action menu and shortcuts? Could you explain what your PR does differently, just to help me understand. Thanks! |
|
@mikebronner Thank you for the question and for your time reviewing my PR! The existing code actions (via textDocument/codeAction) are great for on-demand fixes through the quick action menu. What this PR adds is textDocument/formatting support — a different LSP capability. The key benefit is that it lets users enable format-on-save (by setting "format_on_save": "on" in their Zed settings) so phpcbf runs automatically every time they save. It also hooks into Zed's standard "Format Document" command (Cmd+Shift+I), making it feel like a native formatter rather than a manual code action. In short: code actions = manual trigger from quick action menu; formatting = integrates with Zed's formatting pipeline (format-on-save, format keybinding, formatter selection). |
|
@s3rgiosan thank you for clarifying the difference. That makes a lot of sense! Thank you for working on this feature :) I will review and integrate your PR this week. |
|
@s3rgiosan I made some changes to how the fix on save was implemented, as this is not really a formatter, but a linter fixer. please see the readme on how to update the settings for this. This way it will work collaboratively with other linter fixers as well as document formatters. Please let me know if you run into any issues because of this! Thanks again for your work on this PR. :) The extension update is currently awaiting approval: zed-industries/extensions#5221 |
Fixes #55
Fixes #46
Summary
Adds
textDocument/formattingsupport so users can format PHP files using PHPCBF directly from Zed viaCmd+Shift+Ior format-on-save.textDocument/formattingin the Tower-LSP server, reusing the existingrun_phpcbfinfrastructure. Returns a full-documentTextEditwhen phpcbf makes changes.documentFormattingProvider: truein the server's initialize response.PHPCS_PATH/PHPCBF_PATHenvironment variable support and unifies the detection priority for both tools:vendor/bin(Composer)$PATHextension.tomlno longer setsstandard = "PSR12", allowing PHPCS/PHPCBF to respect the user's global config, project config files, or Zed settings without interference.Configuration
{ "languages": { "PHP": { "language_servers": ["intelephense", "phpcs", "!phpactor"], "formatter": { "language_server": { "name": "phpcs" } }, "format_on_save": "on" } } }Test plan
Cmd+Shift+I— phpcbf fixes are appliedformat_on_save— formatting triggers on savephpcs.xml— both linting and formatting use the project standardPHPCBF_PATHenv var — binary is discovered correctly