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.

Version Downloads

๐Ÿš€ 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-expect and @mago-ignore
  • Block-level suppression for code blocks
  • Workspace-wide suppression via mago.toml
  • Configurable visibility for each suppression type

๐Ÿ› ๏ธ Commands

CommandDescriptionShortcut
Mago: Analyze WorkspaceRun analysis on entire workspace-
Mago: Analyze Current FileRun analysis on current file-

โš™๏ธ Configuration

Core Settings

SettingDescriptionDefault
mago.pathPath to Mago binary (blank = auto-detect)""
mago.runOnWhen to run analysissave
mago.debounceMsDebounce delay for on-type analysis400
mago.minimumFailLevelMinimum issue level to showerror

Analysis Settings

SettingDescriptionDefault
mago.analysis.apply.allowUnsafeAllow unsafe suggestionsfalse
mago.analysis.apply.allowPotentiallyUnsafeAllow potentially unsafe suggestionsfalse

Suppression Settings

SettingDescriptionDefault
mago.analysis.suppress.showLineExpectShow line-level expect actionstrue
mago.analysis.suppress.showLineIgnoreShow line-level ignore actionstrue
mago.analysis.suppress.showBlockIgnoreShow block-level ignore actionstrue
mago.analysis.suppress.showBlockExpectShow block-level expect actionstrue
mago.analysis.suppress.showWorkspaceIgnoreShow workspace ignore actionstrue

๐Ÿ“‹ Requirements

  • Mago CLI installed and available
  • PHP project with Composer (recommended)
  • VS Code 1.103.0 or higher

๐Ÿš€ Quick Start

  1. Install the extension from the VS Code Marketplace
  2. Ensure Mago is installed in your project:
    composer require --dev mago/mago
    
  3. Create a mago.toml file 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
  4. 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

  1. Analysis Trigger: Extension runs Mago analysis based on your mago.runOn setting
  2. Issue Detection: Mago scans your PHP code for issues and violations
  3. Diagnostic Display: Issues appear as squiggles in the editor and in the Problems panel
  4. Quick Fixes: Click the lightbulb icon to apply suggested fixes
  5. 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.toml exists in project root
  • Check the Output panel for error messages

Analysis not running?

  • Ensure mago.runOn is set correctly
  • Check if Mago binary path is correct
  • Try running "Mago: Analyze Workspace" manually

Too many issues?

  • Adjust mago.minimumFailLevel setting
  • Use suppression actions to hide specific issues
  • Configure mago.toml to exclude directories

๐Ÿ“š Learn More

๐Ÿค 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