Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

TableErrorFormatter: Link path in JetBrain IDEs #4369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
ondrejmirtes merged 1 commit into phpstan:2.1.x from vrana:jetbrains
Sep 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Command/ErrorFormatter/TableErrorFormatter.php
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ public function formatErrors(
$message .= '💡 ' . $tip;
}
}
if (is_string($this->editorUrl)) {

if (getenv('TERMINAL_EMULATOR') === 'JetBrains-JediTerm') {
$title = $this->relativePathHelper->getRelativePath($filePath);
$message .= sprintf("\nat %s:%d", $title, $error->getLine());

} elseif (is_string($this->editorUrl)) {
$url = str_replace(
['%file%', '%relFile%', '%line%'],
[$filePath, $this->simpleRelativePathHelper->getRelativePath($filePath), (string) $error->getLine()],
Expand Down
37 changes: 33 additions & 4 deletions tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,23 @@
class TableErrorFormatterTest extends ErrorFormatterTestCase
{

private string|false $terminalEmulator;

#[Override]
protected function setUp(): void
{
putenv('GITHUB_ACTIONS');

$this->terminalEmulator = getenv('TERMINAL_EMULATOR');
putenv('TERMINAL_EMULATOR');
}

#[Override]
protected function tearDown(): void
{
putenv('COLUMNS');
putenv('TERM_PROGRAM');
putenv('TERMINAL_EMULATOR' . ($this->terminalEmulator !== false ? '=' . $this->terminalEmulator : ''));
}

public static function dataFormatterOutputProvider(): iterable
Expand Down Expand Up @@ -226,6 +232,33 @@ public static function dataFormatterOutputProvider(): iterable

[ERROR] Found 1 error

',
];

yield [
'message' => 'Errors in JetBrains',
'exitCode' => 1,
'numFileErrors' => [5, 1],
'numGenericErrors' => 1,
'verbose' => true,
'extraEnvVars' => ['TERMINAL_EMULATOR=JetBrains-JediTerm'],
'expected' => ' ------ ----------------
Line foo.php
------ ----------------
5 Foobar\Buz
🪪 foobar.buz
💡 a tip
at foo.php:5
------ ----------------

-- ---------------------
Error
-- ---------------------
first generic error
-- ---------------------

[ERROR] Found 2 errors

',
];
}
Expand Down Expand Up @@ -271,10 +304,6 @@ public function testEditorUrlWithTrait(): void

public function testEditorUrlWithRelativePath(): void
{
if (getenv('TERMINAL_EMULATOR') === 'JetBrains-JediTerm') {
$this->markTestSkipped('PhpStorm console does not support links in console.');
}

$formatter = $this->createErrorFormatter('editor://custom/path/%relFile%/%line%');
$error = new Error('Test', 'Foo.php', 12, filePath: self::DIRECTORY_PATH . '/rel/Foo.php');
$formatter->formatErrors(new AnalysisResult([$error], [], [], [], [], false, null, true, 0, false, []), $this->getOutput(true));
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /