🧩 Visual Studio Code Recipe
Integrate Mago directly into Visual Studio Code for powerful, automatic PHP code formatting.
This guide uses the Custom Local Formatters extension to connect Mago to VS Code's formatting engine.
Prerequisites
- Mago Installed: Ensure you have installed Mago by following the Installation Guide.
PATH
Configured: Themago
executable must be available in your system'sPATH
. The recommended installation methods configure this for you.
Configuration
Step 1: Install the Extension
First, you need to install the bridge extension that allows VS Code to run Mago as a formatter.
- Open the Extensions view in VS Code (
Ctrl+Shift+X
). - Search for
Custom Local Formatters
. - Install the extension created by
jkillian
.
Step 2: Configure settings.json
Next, you'll configure the extension to use Mago and tell VS Code to use it for PHP files.
Open your user
settings.json
file. You can do this by opening the Command Palette (Ctrl+Shift+P
) and searching for "Open User Settings (JSON)".Add the following configuration to your
settings.json
. If you already have these settings, merge them accordingly.json{ // ... your other settings // 1. Define the Mago command for the formatter extension. "customLocalFormatters.formatters": [ { "command": "mago format --stdin-input", "languages": ["php"] } ], // 2. Configure VS Code to use this extension for PHP files. "[php]": { // Set the custom formatter as the default for PHP. "editor.defaultFormatter": "jkillian.custom-local-formatters", // Recommended: automatically format files on save. "editor.formatOnSave": true } }
Save the
settings.json
file. You may need to restart VS Code for all changes to take effect.
Usage
Your setup is now complete.
- With
editor.formatOnSave
enabled, your PHP files will be automatically formatted by Mago every time you save. - You can also manually format a file at any time by opening the Command Palette (
Ctrl+Shift+P
) and running the Format Document command.