Skip to content

Commit 23771d1

Browse files
vranaondrejmirtes
authored andcommitted
TableErrorFormatter: Link path in JetBrain IDEs
1 parent f17b079 commit 23771d1

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

src/Command/ErrorFormatter/TableErrorFormatter.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@ public function formatErrors(
108108
$message .= '💡 ' . $tip;
109109
}
110110
}
111-
if (is_string($this->editorUrl)) {
111+
112+
if (getenv('TERMINAL_EMULATOR') === 'JetBrains-JediTerm') {
113+
$title = $this->relativePathHelper->getRelativePath($filePath);
114+
$message .= sprintf("\nat %s:%d", $title, $error->getLine());
115+
116+
} elseif (is_string($this->editorUrl)) {
112117
$url = str_replace(
113118
['%file%', '%relFile%', '%line%'],
114119
[$filePath, $this->simpleRelativePathHelper->getRelativePath($filePath), (string) $error->getLine()],

tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,23 @@
1717
class TableErrorFormatterTest extends ErrorFormatterTestCase
1818
{
1919

20+
private string|false $terminalEmulator;
21+
2022
#[Override]
2123
protected function setUp(): void
2224
{
2325
putenv('GITHUB_ACTIONS');
26+
27+
$this->terminalEmulator = getenv('TERMINAL_EMULATOR');
28+
putenv('TERMINAL_EMULATOR');
2429
}
2530

2631
#[Override]
2732
protected function tearDown(): void
2833
{
2934
putenv('COLUMNS');
3035
putenv('TERM_PROGRAM');
36+
putenv('TERMINAL_EMULATOR' . ($this->terminalEmulator !== false ? '=' . $this->terminalEmulator : ''));
3137
}
3238

3339
public static function dataFormatterOutputProvider(): iterable
@@ -226,6 +232,33 @@ public static function dataFormatterOutputProvider(): iterable
226232
227233
[ERROR] Found 1 error
228234
235+
',
236+
];
237+
238+
yield [
239+
'message' => 'Errors in JetBrains',
240+
'exitCode' => 1,
241+
'numFileErrors' => [5, 1],
242+
'numGenericErrors' => 1,
243+
'verbose' => true,
244+
'extraEnvVars' => ['TERMINAL_EMULATOR=JetBrains-JediTerm'],
245+
'expected' => ' ------ ----------------
246+
Line foo.php
247+
------ ----------------
248+
5 Foobar\Buz
249+
🪪 foobar.buz
250+
💡 a tip
251+
at foo.php:5
252+
------ ----------------
253+
254+
-- ---------------------
255+
Error
256+
-- ---------------------
257+
first generic error
258+
-- ---------------------
259+
260+
[ERROR] Found 2 errors
261+
229262
',
230263
];
231264
}
@@ -271,10 +304,6 @@ public function testEditorUrlWithTrait(): void
271304

272305
public function testEditorUrlWithRelativePath(): void
273306
{
274-
if (getenv('TERMINAL_EMULATOR') === 'JetBrains-JediTerm') {
275-
$this->markTestSkipped('PhpStorm console does not support links in console.');
276-
}
277-
278307
$formatter = $this->createErrorFormatter('editor://custom/path/%relFile%/%line%');
279308
$error = new Error('Test', 'Foo.php', 12, filePath: self::DIRECTORY_PATH . '/rel/Foo.php');
280309
$formatter->formatErrors(new AnalysisResult([$error], [], [], [], [], false, null, true, 0, false, []), $this->getOutput(true));

0 commit comments

Comments
 (0)