(Added) Mago static analysis and lint diagnostics by MarjovanLier · Pull Request #3052 · phpactor/phpactor · GitHub
Skip to content

(Added) Mago static analysis and lint diagnostics#3052

Merged
dantleech merged 1 commit into
phpactor:masterfrom
MarjovanLier:feature/summon-the-mago
Jun 25, 2026
Merged

(Added) Mago static analysis and lint diagnostics#3052
dantleech merged 1 commit into
phpactor:masterfrom
MarjovanLier:feature/summon-the-mago

Conversation

@MarjovanLier

Copy link
Copy Markdown
Contributor

Phpactor already surfaces static analysis in the editor through PHPStan and Psalm, but offered no way to use Mago, the Rust PHP toolchain that runs considerably faster and understands the same PHPStan and Psalm annotations. A new optional LanguageServerMago extension closes that gap by registering two language server diagnostics providers that mirror the existing integrations: the mago provider runs mago analyze for static analysis, and the mago-lint provider runs mago lint for style and code smells. The current buffer is streamed to Mago over standard input so results update as you type, and its JSON report is mapped to LSP diagnostics with precise byte-offset ranges and related information for secondary spans. The extension is disabled by default; once enabled, analysis is active immediately while the linter remains an explicit opt-in, and a configuration suggestor offers to switch it on when the carthage-software/mago Composer package is detected. Developers who enable it gain live Mago diagnostics in their editor alongside the existing PHPStan and Psalm output, with no change in behaviour for anyone who leaves it off.

Copilot AI review requested due to automatic review settings June 23, 2026 16:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new optional LanguageServerMago integration to surface Mago diagnostics in Phpactor’s language server, paralleling the existing PHPStan/Psalm integrations.

Changes:

  • Registers two new diagnostics providers: mago (mago analyze) and mago-lint (mago lint), with separate enable flags.
  • Implements a process runner + JSON diagnostics parser that maps Mago byte offsets into LSP ranges and supports related information from secondary spans.
  • Adds configuration suggestor, documentation, fixtures, and unit/smoke tests for the integration.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/Phpactor.php Registers the new Mago extension + suggest extension in the default extension list.
lib/Extension/LanguageServerMago/Provider/MagoDiagnosticProvider.php DiagnosticsProvider wrapper that conditionally delegates to a linter implementation.
lib/Extension/LanguageServerMago/Model/MagoProcess.php Runs the Mago binary with stdin streaming + timeout/cancellation handling and parses JSON output.
lib/Extension/LanguageServerMago/Model/MagoConfig.php Holds Mago executable path, timeout, and optional config file path.
lib/Extension/LanguageServerMago/Model/DiagnosticsParser.php Converts Mago JSON issues into LSP diagnostics (ranges, severity, related information).
lib/Extension/LanguageServerMago/Model/Linter.php Linter interface used by the provider.
lib/Extension/LanguageServerMago/Model/Linter/MagoLinter.php Lints a single document by deriving a workspace-relative path and invoking MagoProcess.
lib/Extension/LanguageServerMago/Model/Linter/TestLinter.php Test double for the linter interface.
lib/Extension/LanguageServerMago/LanguageServerMagoExtension.php Wires MagoProcess + registers two tagged diagnostics providers (mago, mago-lint).
lib/Extension/LanguageServerMago/LanguageServerMagoSuggestExtension.php Adds a Composer-based config suggestor to enable the Mago extension when the package is detected.
lib/Extension/LanguageServerMago/Tests/Provider/MagoDiagnosticProviderTest.php Verifies provider enable/disable behavior and naming.
lib/Extension/LanguageServerMago/Tests/Model/MagoRealBinaryTest.php Smoke test against a real mago binary when present on PATH.
lib/Extension/LanguageServerMago/Tests/Model/MagoProcessTest.php Verifies process invocation, args ordering, stdin piping, timeout, and cancellation behavior.
lib/Extension/LanguageServerMago/Tests/Model/DiagnosticsParserTest.php Verifies parsing, related info extraction, and byte-offset→UTF-16 position mapping.
lib/Extension/LanguageServerMago/Tests/LanguageServerMagoExtensionTest.php Ensures both diagnostics providers are registered and named correctly.
lib/Extension/LanguageServerMago/Tests/LanguageServerMagoSuggestExtensionTest.php Ensures the suggestor is registered under the configuration suggestor tag.
lib/Extension/LanguageServerMago/Tests/Fixtures/analyze.json Real-world mago analyze JSON fixture for parser coverage.
lib/Extension/LanguageServerMago/Tests/Fixtures/lint.json Real-world mago lint JSON fixture for parser coverage.
doc/integrations/mago.rst User documentation for enabling/configuring the Mago integration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/Extension/LanguageServerMago/Model/MagoProcess.php Outdated
@MarjovanLier MarjovanLier force-pushed the feature/summon-the-mago branch 2 times, most recently from b494284 to 9bafa55 Compare June 23, 2026 16:53
Comment thread doc/integrations/mago.rst Outdated
Comment thread doc/integrations/mago.rst Outdated
Comment thread lib/Extension/LanguageServerMago/Model/Linter/MagoLinter.php Outdated
Comment thread lib/Extension/LanguageServerMago/Model/Linter/MagoLinter.php Outdated
Comment thread lib/Extension/LanguageServerMago/Tests/Model/DiagnosticsParserTest.php Outdated
Comment thread lib/Extension/LanguageServerMago/Tests/Model/MagoProcessTest.php Outdated
Comment thread lib/Extension/LanguageServerMago/Tests/Model/MagoProcessTest.php Outdated
Comment thread lib/Extension/LanguageServerMago/Tests/Model/MagoProcessTest.php Outdated
Comment thread lib/Extension/LanguageServerMago/Tests/Model/MagoProcessTest.php Outdated
Comment thread lib/Extension/LanguageServerMago/Tests/Model/MagoProcessTest.php Outdated
Comment thread lib/Extension/LanguageServerMago/Tests/Model/MagoProcessTest.php
Comment thread lib/Extension/LanguageServerMago/Tests/Model/MagoRealBinaryTest.php Outdated
@MarjovanLier MarjovanLier force-pushed the feature/summon-the-mago branch from 9bafa55 to 1bd2037 Compare June 24, 2026 18:08
Surface diagnostics from the Mago toolchain (a Rust PHP linter,
formatter and static analysis tool) in the language server, giving
users a fast alternative to the existing PHPStan and Psalm
integrations.

Two providers are registered as an optional extension: "mago" runs
"mago analyze" for static analysis and "mago-lint" runs "mago lint"
for style and code smells. The current buffer is streamed to Mago on
stdin so diagnostics update as you type, and the JSON report is mapped
to LSP diagnostics with precise byte-offset ranges and related
information for secondary spans.

The extension is disabled by default. When enabled, analysis is on and
the linter is opt-in. A suggestor offers to enable it when the
carthage-software/mago Composer package is present.

Signed-off-by: Marjo Wenzel van Lier <marjo.vanlier@gmail.com>
@MarjovanLier MarjovanLier force-pushed the feature/summon-the-mago branch from 1bd2037 to 558ff8c Compare June 24, 2026 18:38
* Runs `mago <subcommand> --reporting-format=json --stdin-input <relative path>`
* with the document text piped on stdin, and parses the result.
*
* Mago is a native (Rust) binary, so the command is run directly without a PHP

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, isn't the wrapper in vendor/bin a PHP script?

@dantleech dantleech merged commit 1b0834e into phpactor:master Jun 25, 2026
13 checks passed
@dantleech

Copy link
Copy Markdown
Collaborator

looks good, thanks

@MarjovanLier MarjovanLier deleted the feature/summon-the-mago branch June 25, 2026 17:45
@MarjovanLier

Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants