Skip to content

Commit eae961c

Browse files
caufangondrejmirtes
authored andcommitted
Ensure that JetBrains terminal sees correct relative path.
1 parent 7b001c8 commit eae961c

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Command/ErrorFormatter/TableErrorFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function formatErrors(
110110
}
111111

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

116116
} elseif (is_string($this->editorUrl)) {

tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,30 @@ public function testBug13317(): void
424424
);
425425
}
426426

427+
public function testJetBrainsTerminalRelativePath(): void
428+
{
429+
putenv('TERMINAL_EMULATOR=JetBrains-JediTerm');
430+
431+
// FuzzyRelativePathHelper trims path segments based on analysed paths.
432+
$relativePathHelper = new FuzzyRelativePathHelper(new NullRelativePathHelper(), self::DIRECTORY_PATH, [self::DIRECTORY_PATH . '/rel'], '/');
433+
434+
$formatter = new TableErrorFormatter(
435+
$relativePathHelper,
436+
new SimpleRelativePathHelper(self::DIRECTORY_PATH),
437+
new CiDetectedErrorFormatter(
438+
new GithubErrorFormatter($relativePathHelper),
439+
new TeamcityErrorFormatter($relativePathHelper),
440+
),
441+
false,
442+
null,
443+
null,
444+
);
445+
$error = new Error('Test', 'Foo.php', 12, filePath: self::DIRECTORY_PATH . '/rel/Foo.php');
446+
$formatter->formatErrors(new AnalysisResult([$error], [], [], [], [], false, null, true, 0, false, []), $this->getOutput(true));
447+
448+
$this->assertStringContainsString('at rel/Foo.php:12', $this->getOutputContent(true));
449+
}
450+
427451
private function createErrorFormatter(?string $editorUrl, ?string $editorUrlTitle = null): TableErrorFormatter
428452
{
429453
$relativePathHelper = new FuzzyRelativePathHelper(new NullRelativePathHelper(), self::DIRECTORY_PATH, [], '/');

0 commit comments

Comments
 (0)