[6.x] extract IdeDetector, auto-detect IDE when none specified#11802
[6.x] extract IdeDetector, auto-detect IDE when none specified#11802
IdeDetector, auto-detect IDE when none specified#11802Conversation
…ar on Darwin Hardcoding '/Applications/PhpStorm.app' breaks JetBrains Toolbox installs, which default to ~/Applications/. Use `open -b com.jetbrains.PhpStorm` instead, which resolves the correct .app via the OS app registry regardless of install path. Also respect the PHPSTORM env var on Darwin (previously ignored), consistent with the non-Darwin behaviour. Uses assignment-in-condition to call getenv once. Fixes vimeo#11800
IdeDetector, auto-detect IDE when none specified
Without -n, macOS open(1) does not forward --args to an already-running application — it only brings it to the front. Since PhpStorm is almost always running during a review session, --line/--column/file would be silently ignored. Consistent with the open -na path and the env-var path.
Add IdeDetector::detect() which reads env vars injected by IDE integrated terminals (TERMINAL_EMULATOR for JetBrains, VSCODE_PROXY_URI for code-server, TERM_PROGRAM=vscode for VS Code desktop) and returns the matching mode key. - psalm-review now auto-detects the IDE when the mode argument is omitted, falling back to an error only when running outside a supported terminal - Psalm.php's findDefaultOutputFormat() delegates to IdeDetector instead of duplicating the TERMINAL_EMULATOR check inline - IdeDetector added to PreloaderList in alphabetical order
…_VS_CODE Rename constants for clarity and namespace safety: PHPSTORM → IDE_PHPSTORM CODE → IDE_VS_CODE CODE_SERVER → IDE_VS_CODE_SERVER Update @return annotation to self::IDE_*|null. Update all call sites (Psalm.php, Review.php match arms).
…to-detection When the IDE argument is omitted, array_shift() on a non-null filter arg (e.g. ~SomeIssue) would consume it as the mode key, hitting the default match arm with a confusing error. Instead, peek at args[0] and only consume it if it matches a known IDE name; otherwise fall through to IdeDetector::detect().
e0a3f25 to
fad90ab
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 4f287f5. Configure here.
| 'No IDE was specified and none could be auto-detected. ' . | ||
| "Pass 'code', 'phpstorm', or 'code-server' as the second argument.", | ||
| ); | ||
| } |
There was a problem hiding this comment.
Missing require_once for IdeDetector breaks direct invocation
Medium Severity
Review.php manually requires all its dependencies via require_once (lines 47–51) to support direct invocation from the repo root via ./psalm-review, which bypasses Composer's autoloader. The new IdeDetector dependency is used at line 85 (IdeDetector::IDE_PHPSTORM, etc.) but has no corresponding require_once __DIR__ . '/IdeDetector.php' entry. This causes a fatal "Class not found" error when running ./psalm-review directly. The psalm --review path is unaffected because Psalm::run() loads the autoloader before requiring Review.php.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 4f287f5. Configure here.


Stacks on top of #11801 (includes those commits; best reviewed from that PR's base).
IdeDetector::detect()— a single place for reading IDE env vars across the codebasepsalm-reviewnow auto-detects the IDE when the mode argument is omitted; falls back to a clear error only when no supported IDE is detectedPsalm::findDefaultOutputFormat()delegates toIdeDetectorinstead of duplicating theTERMINAL_EMULATORcheck inlineIdeDetectoradded toPreloaderListin alphabetical orderDetection logic
TERMINAL_EMULATORJetBrains(existing Psalm convention)VSCODE_PROXY_URITERM_PROGRAMvscodeAuto-detection only works in the IDE's integrated terminal — external terminals still require an explicit argument.
Note
Medium Risk
Changes CLI argument parsing and environment-based IDE detection for
psalm-review, which could affect developer workflows and IDE launching if detection/argument consumption is wrong. Scope is limited to CLI tooling and documentation updates.Overview
Adds a new internal
IdeDetectorutility to centralize IDE detection via integrated-terminal environment variables (PhpStorm/JetBrains, VS Code, and code-server).Updates
psalm-reviewso the IDE argument is optional: it now only consumes the next arg if it matches a known IDE, otherwise it treats it as an issue-type filter and falls back to auto-detection (failing with a clearer error when nothing is detected).Psalm::findDefaultOutputFormat()is also updated to useIdeDetectorfor PhpStorm default output selection, and the docs/help text are updated accordingly;IdeDetectoris added to the preloader list.Reviewed by Cursor Bugbot for commit 4f287f5. Bugbot is set up for automated code reviews on this repo. Configure here.