close
Skip to content

[6.x] extract IdeDetector, auto-detect IDE when none specified#11802

Open
alies-dev wants to merge 6 commits intovimeo:6.xfrom
alies-dev:fix/11800-ide-detector
Open

[6.x] extract IdeDetector, auto-detect IDE when none specified#11802
alies-dev wants to merge 6 commits intovimeo:6.xfrom
alies-dev:fix/11800-ide-detector

Conversation

@alies-dev
Copy link
Copy Markdown
Contributor

@alies-dev alies-dev commented Apr 14, 2026

Stacks on top of #11801 (includes those commits; best reviewed from that PR's base).

  • Adds IdeDetector::detect() — a single place for reading IDE env vars across the codebase
  • psalm-review now auto-detects the IDE when the mode argument is omitted; falls back to a clear error only when no supported IDE is detected
  • Psalm::findDefaultOutputFormat() delegates to IdeDetector instead of duplicating the TERMINAL_EMULATOR check inline
  • IdeDetector added to PreloaderList in alphabetical order

Detection logic

IDE Env var Value
PhpStorm / JetBrains TERMINAL_EMULATOR starts with JetBrains (existing Psalm convention)
code-server VSCODE_PROXY_URI any (only set by code-server, not desktop VS Code)
VS Code desktop TERM_PROGRAM vscode

Auto-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 IdeDetector utility to centralize IDE detection via integrated-terminal environment variables (PhpStorm/JetBrains, VS Code, and code-server).

Updates psalm-review so 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 use IdeDetector for PhpStorm default output selection, and the docs/help text are updated accordingly; IdeDetector is 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.

…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
Comment thread src/Psalm/Internal/Cli/Review.php Outdated
Comment thread src/Psalm/Internal/Cli/Review.php Outdated
@alies-dev alies-dev changed the title feat(review): extract IdeDetector, auto-detect IDE when none specified [6.x] extract IdeDetector, auto-detect IDE when none specified Apr 14, 2026
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().
@alies-dev alies-dev force-pushed the fix/11800-ide-detector branch from e0a3f25 to fad90ab Compare April 14, 2026 08:27
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

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.",
);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4f287f5. Configure here.

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.

1 participant