Skip to content
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
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
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