Skip to content

Commit 861bf06

Browse files
committed
added clickable hyperlinks for callstack file paths with line numbers
1 parent de3f127 commit 861bf06

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

src/Framework/Ansi.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ public static function link(string $text, string $url): string
5858

5959

6060
/**
61-
* Creates file:// URL from absolute path.
61+
* Creates file:// URL from absolute path, optionally with line number.
6262
*/
63-
public static function fileUrl(string $path): string
63+
public static function fileUrl(string $path, ?int $line = null): string
6464
{
6565
$path = strtr($path, '\\', '/');
66-
return 'file:///' . ltrim($path, '/');
66+
$url = 'file:///' . ltrim($path, '/');
67+
return $line !== null ? "$url:$line" : $url;
6768
}
6869

6970

src/Framework/Dumper.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,14 @@ public static function dumpException(\Throwable $e): string
366366
. ($item['file']
367367
? (
368368
($item['file'] === $testFile ? Ansi::color('white') : '')
369-
. implode(
370-
self::$pathSeparator ?? DIRECTORY_SEPARATOR,
371-
array_slice(explode(DIRECTORY_SEPARATOR, $item['file']), -self::$maxPathSegments),
369+
. Ansi::link(
370+
implode(
371+
self::$pathSeparator ?? DIRECTORY_SEPARATOR,
372+
array_slice(explode(DIRECTORY_SEPARATOR, $item['file']), -self::$maxPathSegments),
373+
) . "($item[line])",
374+
Ansi::fileUrl($item['file'], $item['line']),
372375
)
373-
. "($item[line])" . Ansi::color('gray') . ' '
376+
. Ansi::color('gray') . ' '
374377
)
375378
: '[internal function]'
376379
)

0 commit comments

Comments
 (0)