Skip to content

Commit

Permalink
Merge pull request #4160 from Rarst/patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Nov 27, 2021
2 parents 03aea28 + ec1571d commit 66eb665
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/Psalm/Report/ConsoleReport.php
Expand Up @@ -6,8 +6,10 @@
use Psalm\Internal\Analyzer\IssueData;
use Psalm\Report;

use function basename;
use function get_cfg_var;
use function ini_get;
use function strlen;
use function strtr;
use function substr;

Expand Down Expand Up @@ -118,6 +120,15 @@ private function getFileReference($data): string
return $reference;
}

$file_basename = basename($data->file_name);
$file_path = substr($data->file_name, 0, -strlen($file_basename));

$reference = $file_path
. "\033[1;31m"
. $file_basename . ':' . $data->line_from . ':' . $data->column_from
. "\033[0m"
;

if (null === $this->link_format) {
// if xdebug is not enabled, use `get_cfg_var` to get the value directly from php.ini
$this->link_format = ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format')
Expand All @@ -127,6 +138,7 @@ private function getFileReference($data): string
$link = strtr($this->link_format, ['%f' => $data->file_path, '%l' => $data->line_from]);
// $reference = $data->file_name . ':' . $data->line_from . ':' . $data->column_from;


return "\033]8;;" . $link . "\033\\" . $reference . "\033]8;;\033\\";
}
}
2 changes: 1 addition & 1 deletion tests/ReportOutputTest.php
Expand Up @@ -1079,7 +1079,7 @@ public function testConsoleReportWithLinks(): void
$output = IssueBuffer::getOutput(IssueBuffer::getIssuesData(), $console_report_options);

$this->assertStringContainsString(
"\033]8;;file://somefile.php#L3\033\\somefile.php:3:10\033]8;;\033\\",
"\033]8;;file://somefile.php#L3\033\\\033[1;31msomefile.php:3:10\033[0m\033]8;;\033\\",
$output
);
}
Expand Down

0 comments on commit 66eb665

Please sign in to comment.