Mago (Unofficial) - VS Code Extension
September 28, 2025 ยท View on GitHub
Unofficial VS Code extension for Mago PHP analyzer - Get instant code analysis, quick fixes, and intelligent diagnostics directly in your editor.
๐ Features
โก Real-time Analysis
- Workspace-wide analysis on startup, save, or as you type
- Instant diagnostics with precise error highlighting
- Auto-discovery of Mago binary from Composer
- Performance optimized with smart re-analysis
๐ง Smart Quick Fixes
- One-click fixes for common issues
- Safety gating for potentially unsafe suggestions
- Configurable safety levels (Safe, Potentially Unsafe, Unsafe)
- Intelligent code suggestions from Mago
๐ฏ Issue Suppression
- Line-level suppression with
@mago-expectand@mago-ignore - Block-level suppression for code blocks
- Workspace-wide suppression via
mago.toml - Configurable visibility for each suppression type
๐ ๏ธ Commands
| Command | Description | Shortcut |
|---|---|---|
Mago: Analyze Workspace | Run analysis on entire workspace | - |
Mago: Analyze Current File | Run analysis on current file | - |
โ๏ธ Configuration
Core Settings
| Setting | Description | Default |
|---|---|---|
mago.path | Path to Mago binary (blank = auto-detect) | "" |
mago.runOn | When to run analysis | save |
mago.debounceMs | Debounce delay for on-type analysis | 400 |
mago.minimumFailLevel | Minimum issue level to show | error |
Analysis Settings
| Setting | Description | Default |
|---|---|---|
mago.analysis.apply.allowUnsafe | Allow unsafe suggestions | false |
mago.analysis.apply.allowPotentiallyUnsafe | Allow potentially unsafe suggestions | false |
Suppression Settings
| Setting | Description | Default |
|---|---|---|
mago.analysis.suppress.showLineExpect | Show line-level expect actions | true |
mago.analysis.suppress.showLineIgnore | Show line-level ignore actions | true |
mago.analysis.suppress.showBlockIgnore | Show block-level ignore actions | true |
mago.analysis.suppress.showBlockExpect | Show block-level expect actions | true |
mago.analysis.suppress.showWorkspaceIgnore | Show workspace ignore actions | true |
๐ Requirements
- Mago CLI installed and available
- PHP project with Composer (recommended)
- VS Code 1.103.0 or higher
๐ Quick Start
- Install the extension from the VS Code Marketplace
- Ensure Mago is installed in your project:
composer require --dev mago/mago - Create a
mago.tomlfile in your project root (extension will help you create one)- Use the provided schema for IntelliSense and validation
- See mago.toml.example for a complete configuration example
- Start coding! The extension will automatically analyze your PHP files
๐ Project Structure
your-project/
โโโ mago.toml # Mago configuration
โโโ mago.toml.schema.json # JSON schema for IntelliSense (optional)
โโโ vendor/
โ โโโ bin/
โ โโโ mago # Mago binary (auto-detected)
โโโ src/
โโโ your-php-files.php
๐ Configuration Schema
The extension includes a comprehensive JSON schema for mago.toml files that matches the official Mago configuration format:
- IntelliSense support - Auto-completion and validation in VS Code
- Type checking - Validates PHP versions, paths, and configuration options
- Documentation - Inline help for all configuration options
- Examples - Real-world configuration examples
Configuration Structure:
# Global Options
php-version = "8.4"
threads = 8
stack-size = 8388608
[source]
paths = ["src", "tests"]
excludes = ["vendor/", "cache/"]
extensions = ["php", "php8"]
[linter]
# Linter-specific options
[formatter]
# Formatter-specific options
[analyzer]
# Analyzer-specific options
To use the schema, add this to your mago.toml file:
#:schema https://raw.githubusercontent.com/kgz/mago_vscode/v0/mago.toml.schema.json
๐ How It Works
- Analysis Trigger: Extension runs Mago analysis based on your
mago.runOnsetting - Issue Detection: Mago scans your PHP code for issues and violations
- Diagnostic Display: Issues appear as squiggles in the editor and in the Problems panel
- Quick Fixes: Click the lightbulb icon to apply suggested fixes
- Suppression: Use code actions to suppress specific issues
๐๏ธ Analysis Modes
- On Save (default): Analyzes when you save files
- On Type: Analyzes as you type (with debouncing)
- Manual: Only analyzes when you run commands
๐ก๏ธ Safety Features
- Vendor Filtering: Third-party code is analyzed but not shown in Problems
- Safety Gating: Unsafe suggestions are disabled by default
- Configurable Levels: Choose which safety levels to allow
๐ Troubleshooting
Common Issues
Extension not working?
- Check if Mago is installed:
composer show mago/mago - Verify
mago.tomlexists in project root - Check the Output panel for error messages
Analysis not running?
- Ensure
mago.runOnis set correctly - Check if Mago binary path is correct
- Try running "Mago: Analyze Workspace" manually
Too many issues?
- Adjust
mago.minimumFailLevelsetting - Use suppression actions to hide specific issues
- Configure
mago.tomlto exclude directories
๐ Learn More
- Mago Documentation - Official Mago analyzer docs
- VS Code Extension API - VS Code extension development
- PHP Best Practices - PHP coding standards
๐ค Contributing
This is an unofficial extension. For issues and feature requests, please visit the GitHub repository.
๐ License
This extension is licensed under the MIT License. The Mago PHP analyzer is also licensed under the MIT License.
See LICENSE file for details.
Made with โค๏ธ for the PHP community