Skip to content

Commit 2e3f240

Browse files
committed
Move IDE file link formats from FrameworkExtension to FileLinkFormatter
1 parent 60de1c9 commit 2e3f240

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Debug/FileLinkFormatter.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@
2424
*/
2525
class FileLinkFormatter
2626
{
27+
private const FORMATS = [
28+
'textmate' => 'txmt://open?url=file://%f&line=%l',
29+
'macvim' => 'mvim://open?url=file://%f&line=%l',
30+
'emacs' => 'emacs://open?url=file://%f&line=%l',
31+
'sublime' => 'subl://open?url=file://%f&line=%l',
32+
'phpstorm' => 'phpstorm://open?file=%f&line=%l',
33+
'atom' => 'atom://core/open/file?filename=%f&line=%l',
34+
'vscode' => 'vscode://file/%f:%l',
35+
];
36+
2737
private $fileLinkFormat;
2838
private $requestStack;
2939
private $baseDir;
@@ -34,7 +44,7 @@ class FileLinkFormatter
3444
*/
3545
public function __construct($fileLinkFormat = null, RequestStack $requestStack = null, string $baseDir = null, $urlFormat = null)
3646
{
37-
$fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
47+
$fileLinkFormat = (self::FORMATS[$fileLinkFormat] ?? $fileLinkFormat) ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
3848
if ($fileLinkFormat && !\is_array($fileLinkFormat)) {
3949
$i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: \strlen($f);
4050
$fileLinkFormat = [substr($f, 0, $i)] + preg_split('/&([^>]++)>/', substr($f, $i), -1, \PREG_SPLIT_DELIM_CAPTURE);

Tests/Debug/FileLinkFormatterTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,13 @@ public function testWhenNoFileLinkFormatAndRequest()
5151

5252
$this->assertSame('http://www.example.org/_profiler/open?file=file.php&line=3#line3', $sut->format($file, 3));
5353
}
54+
55+
public function testIdeFileLinkFormat()
56+
{
57+
$file = __DIR__.\DIRECTORY_SEPARATOR.'file.php';
58+
59+
$sut = new FileLinkFormatter('atom');
60+
61+
$this->assertSame("atom://core/open/file?filename=$file&line=3", $sut->format($file, 3));
62+
}
5463
}

0 commit comments

Comments
 (0)