PHP FormatterPHP Formatter formats your PHP files using a native Rust binary — no Node.js dependencies, no PHP runtime required. Before / After
Features
InstallationFrom the VS Code MarketplaceSearch for PHP Formatter in the Extensions panel ( Or from the command line:
From a VSIX fileDownload the
Or: Extensions panel →
UsageFormat document
Format on saveEnable in VS Code settings:
Or per project in
Skip a region
Both ConfigurationVS Code settingsAll settings live under the
|
| OS | Architecture | Status |
|---|---|---|
| Windows 10 / 11 | x86-64 | ✅ Bundled |
| macOS 12+ | x86-64 | 🔧 Build from source |
| macOS 12+ | Apple Silicon (arm64) | 🔧 Build from source |
| Linux (glibc 2.17+) | x86-64 | 🔧 Build from source |
The published .vsix bundles the Windows x86-64 binary. For other platforms, build the binary from source (see Contributing) and point phpFormatter.binaryPath to it.
Contributing
Requirements
Clone and build
git clone https://github.com/eder-rimarachinr/vscode-extension-php-formater-rust.git
cd php-formatter
Build the Rust binary:
cd php-formatter # Rust crate directory
cargo build --release
# Output: target/release/php_formatter (or .exe on Windows)
Copy the binary into the extension:
# Windows
copy target\release\php_formatter.exe ..\vscode-extension\bin\
# macOS / Linux
cp target/release/php_formatter ../vscode-extension/bin/
Build the VS Code extension:
cd ../vscode-extension
npm install
npm run compile
npx vsce package # produces php-formatter-x.y.z.vsix
Project structure
php-formatter/ Rust binary (cargo project)
├── src/
│ ├── main.rs Entry point — legacy + --json dispatch
│ ├── formatter.rs Line struct, format pipeline
│ ├── config.rs Config struct, .phpfmt.toml discovery
│ ├── protocol.rs BinaryRequest / BinaryResponse types
│ └── rules/
│ ├── align.rs = alignment
│ ├── align_arrows.rs => alignment
│ ├── align_comments.rs Inline comment alignment
│ ├── frozen.rs @fmt-off / @fmt-on regions
│ ├── indent.rs Indentation normalisation
│ └── spacing.rs Operator and comma spacing
├── Cargo.toml
└── .cargo/config.toml Linker config (uses rust-lld)
vscode-extension/ VS Code extension (TypeScript)
├── src/
│ └── extension.ts Activation, commands, providers
├── bin/
│ └── php_formatter.exe Bundled release binary (Windows)
├── package.json
└── tsconfig.json
Running the binary directly
The binary accepts PHP via stdin (legacy mode) or a JSON request on stdin (--json mode):
# Legacy: pipe source, get formatted source on stdout
echo '<?php $a = 1; $foo = 2;' | php_formatter
# JSON mode: send a request object, receive a response object
echo '{"command":"format","source":"<?php $a=1;\n$foo=2;\n"}' | php_formatter --json
# Check mode: returns diagnostics without modifying source
echo '{"command":"check","source":"<?php $a=1;\n"}' | php_formatter --json
Changelog
v0.3.3
- Fixed binary integrity check (checksums.txt had placeholder hashes)
v0.3.2
- Updated README with correct repository links
v0.3.1
- Added extension icon
v0.3.0
- JSON protocol between extension and binary (
--jsonmode) =>alignment for arrays andmatchexpressions- Inline
//comment alignment in consecutive blocks @fmt-off/@fmt-onregion exclusion (PhpStorm@formatter:offalso supported)- Format on save (
phpFormatter.formatOnSave) - Preview diff before applying (
PHP Formatter: Preview Format) - Format selection
- Per-project
.phpfmt.tomlconfiguration with full validation - Problems panel diagnostics with Quick Fix (
phpFormatter.diagnostics) - Bulk format: workspace and folder (
PHP Formatter: Format All PHP Files in Workspace) - Status bar timing (
⌚ PHP fmt: Nms)
v0.1.0 — Initial release
=alignment for consecutive assignment blocks- Indentation normalisation (tabs → spaces)
- Spacing normalisation around operators and commas
- Bundled Windows x86-64 binary
- VS Code formatter provider (
Shift+Alt+F)
Upcoming
- macOS and Linux bundled binaries
License
MIT License.