From 518d01c5cc32d03e63fe854d4e20a3b46c09fde9 Mon Sep 17 00:00:00 2001 From: Martins Ayoola <47458749+omartins365@users.noreply.github.com> Date: Thu, 31 Jul 2025 12:33:30 +0000 Subject: [PATCH 1/4] Add WSL support for Xdebug links and corresponding tests --- README.md | 28 +++++++++++++ src/DebugBar/DataFormatter/HasXdebugLinks.php | 39 ++++++++++++++++++- tests/DebugBar/Tests/HasXdebugLinksTest.php | 20 ++++++++++ 3 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 tests/DebugBar/Tests/HasXdebugLinksTest.php diff --git a/README.md b/README.md index 7fd13e3b..55557d96 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,31 @@ +# VSCode WSL Remote Xdebug Link Support + +This package now supports generating Xdebug file links for VS Code running in WSL (Windows Subsystem for Linux) via the `vscode-wsl` editor type. + +## Usage + +Set the editor link template to `vscode-wsl`: + +```php +$debugbar->setEditorLinkTemplate('vscode-wsl'); +``` + +You can configure the WSL distribution name (e.g., `Ubuntu`) using: + +- The `DEBUGBAR_WSL_NAME` environment variable +- The `setWslName()` method + +If not set, it defaults to `Ubuntu`. + +## Example Link + +The generated link will look like: + +``` +vscode://vscode-remote/wsl+Ubuntu/path/to/file.php:1 +``` + +Clicking this link in your browser on Windows will open the file in VS Code inside your WSL environment. # PHP Debug Bar [![Latest Stable Version](https://img.shields.io/packagist/v/php-debugbar/php-debugbar?label=Stable)](https://packagist.org/packages/php-debugbar/php-debugbar) [![Total Downloads](https://img.shields.io/packagist/dt/maximebf/debugbar?label=Downloads)](https://packagist.org/packages/php-debugbar/php-debugbar) [![License](https://img.shields.io/badge/Licence-MIT-4d9283)](https://packagist.org/packages/php-debugbar/php-debugbar) [![Tests](https://github.com/maximebf/php-debugbar/actions/workflows/run-tests.yml/badge.svg)](https://github.com/php-debugbar/php-debugbar/actions/workflows/run-tests.yml) diff --git a/src/DebugBar/DataFormatter/HasXdebugLinks.php b/src/DebugBar/DataFormatter/HasXdebugLinks.php index 3e83b87f..991231de 100644 --- a/src/DebugBar/DataFormatter/HasXdebugLinks.php +++ b/src/DebugBar/DataFormatter/HasXdebugLinks.php @@ -17,6 +17,34 @@ trait HasXdebugLinks protected $xdebugLinkTemplate = ''; protected $xdebugShouldUseAjax = false; protected $xdebugReplacements = array(); + protected $wslName = null; + /** + * Set the WSL distribution name for vscode-wsl links. + * + * @param string|null $wslName + */ + public function setWslName($wslName) + { + $this->wslName = $wslName; + } + + /** + * Get the WSL distribution name, from property, env, or default. + * + * @return string + */ + public function getWslName() + { + if ($this->wslName) { + return $this->wslName; + } + $env = getenv('DEBUGBAR_WSL_NAME'); + if ($env) { + return $env; + } + // Optionally, set a default here, e.g. 'Ubuntu' + return 'Ubuntu'; + } /** * Shorten the file path by removing the xdebug path replacements @@ -72,10 +100,16 @@ public function getXdebugLink($file, $line = null) } } - $url = strtr($this->getXdebugLinkTemplate(), [ + $template = $this->getXdebugLinkTemplate(); + $replacements = [ '%f' => rawurlencode(str_replace('\\', '/', $file)), '%l' => rawurlencode((string) $line ?: 1), - ]); + ]; + // Add %w for WSL name if needed + if (strpos($template, '%w') !== false) { + $replacements['%w'] = rawurlencode($this->getWslName()); + } + $url = strtr($template, $replacements); if ($url) { return [ 'url' => $url, @@ -119,6 +153,7 @@ public function setEditorLinkTemplate($editor) 'vscode-insiders' => 'vscode-insiders://file/%f:%l', 'vscode-remote' => 'vscode://vscode-remote/%f:%l', 'vscode-insiders-remote' => 'vscode-insiders://vscode-remote/%f:%l', + 'vscode-wsl' => 'vscode://vscode-remote/wsl+%w/%f:%l', 'vscodium' => 'vscodium://file/%f:%l', 'nova' => 'nova://open?path=%f&line=%l', 'xdebug' => 'xdebug://%f@%l', diff --git a/tests/DebugBar/Tests/HasXdebugLinksTest.php b/tests/DebugBar/Tests/HasXdebugLinksTest.php new file mode 100644 index 00000000..9f843045 --- /dev/null +++ b/tests/DebugBar/Tests/HasXdebugLinksTest.php @@ -0,0 +1,20 @@ +setEditorLinkTemplate('vscode-wsl'); + $this->setWslName('CustomWSL'); + $file = '/var/www/html/index.php'; + $line = 42; + $link = $this->getXdebugLink($file, $line); + $this->assertStringContainsString('vscode://vscode-remote/wsl+CustomWSL', $link['url']); + $this->assertStringContainsString('index.php:42', urldecode($link['url'])); + } +} From ad3eb782d4d5d01da74d5350576ea2fddd66fd4d Mon Sep 17 00:00:00 2001 From: Martins Ayoola <47458749+omartins365@users.noreply.github.com> Date: Thu, 31 Jul 2025 13:02:32 +0000 Subject: [PATCH 2/4] Add tests for WSL link generation in HasXdebugLinks --- tests/DebugBar/Tests/HasXdebugLinksTest.php | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/DebugBar/Tests/HasXdebugLinksTest.php b/tests/DebugBar/Tests/HasXdebugLinksTest.php index 9f843045..34bf43ab 100644 --- a/tests/DebugBar/Tests/HasXdebugLinksTest.php +++ b/tests/DebugBar/Tests/HasXdebugLinksTest.php @@ -1,5 +1,7 @@ assertStringContainsString('vscode://vscode-remote/wsl+CustomWSL', $link['url']); $this->assertStringContainsString('index.php:42', urldecode($link['url'])); } + + public function testVscodeWslLinkGenerationWithDefaultWslName() + { + $this->setEditorLinkTemplate('vscode-wsl'); + // Do not set WSL name, should default to 'Ubuntu' + $file = '/var/www/html/test.php'; + $line = 5; + $link = $this->getXdebugLink($file, $line); + $this->assertStringContainsString('vscode://vscode-remote/wsl+Ubuntu', $link['url']); + $this->assertStringContainsString('test.php:5', urldecode($link['url'])); + } + + public function testVscodeWslLinkGenerationWithEnvVar() + { + $this->setEditorLinkTemplate('vscode-wsl'); + putenv('DEBUGBAR_WSL_NAME=EnvWSL'); + // Do not set WSL name via setter, should use env var + $file = '/var/www/html/env.php'; + $line = 7; + $link = $this->getXdebugLink($file, $line); + $this->assertStringContainsString('vscode://vscode-remote/wsl+EnvWSL', $link['url']); + $this->assertStringContainsString('env.php:7', urldecode($link['url'])); + putenv('DEBUGBAR_WSL_NAME'); // Clean up + } } From e3190f68a06c6af229f53efe112d810aa799ef47 Mon Sep 17 00:00:00 2001 From: Martins Ayoola <47458749+omartins365@users.noreply.github.com> Date: Sat, 9 Aug 2025 18:43:29 +0000 Subject: [PATCH 3/4] Update README to clarify WSL Xdebug link template usage --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 55557d96..ef9503ba 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,15 @@ This package now supports generating Xdebug file links for VS Code running in WS Set the editor link template to `vscode-wsl`: ```php -$debugbar->setEditorLinkTemplate('vscode-wsl'); +$wslName = getenv('DEBUGBAR_WSL_NAME') ?: 'Ubuntu'; +$collector->setXdebugLinkTemplate("vscode://vscode-remote/wsl+{$wslName}/%f:%l"); +``` + +Or, if your collector supports a more generic editor link template method: + +```php +// usage: $collector->setEditorLinkTemplate('vscode-remote', 'wsl+Ubuntu'); +$collector->setEditorLinkTemplate('vscode-remote', 'wsl+Ubuntu'); ``` You can configure the WSL distribution name (e.g., `Ubuntu`) using: From c6b70f9bb535cefa476f486ca23bdb5665d4334f Mon Sep 17 00:00:00 2001 From: Martins Ayoola <47458749+omartins365@users.noreply.github.com> Date: Mon, 11 Aug 2025 19:19:10 +0000 Subject: [PATCH 4/4] Add documentation for VSCode WSL Remote Xdebug link support --- README.md | 36 ------------------------------------ docs/vscode_wsl_links.md | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 36 deletions(-) create mode 100644 docs/vscode_wsl_links.md diff --git a/README.md b/README.md index ef9503ba..7fd13e3b 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,3 @@ -# VSCode WSL Remote Xdebug Link Support - -This package now supports generating Xdebug file links for VS Code running in WSL (Windows Subsystem for Linux) via the `vscode-wsl` editor type. - -## Usage - -Set the editor link template to `vscode-wsl`: - -```php -$wslName = getenv('DEBUGBAR_WSL_NAME') ?: 'Ubuntu'; -$collector->setXdebugLinkTemplate("vscode://vscode-remote/wsl+{$wslName}/%f:%l"); -``` - -Or, if your collector supports a more generic editor link template method: - -```php -// usage: $collector->setEditorLinkTemplate('vscode-remote', 'wsl+Ubuntu'); -$collector->setEditorLinkTemplate('vscode-remote', 'wsl+Ubuntu'); -``` - -You can configure the WSL distribution name (e.g., `Ubuntu`) using: - -- The `DEBUGBAR_WSL_NAME` environment variable -- The `setWslName()` method - -If not set, it defaults to `Ubuntu`. - -## Example Link - -The generated link will look like: - -``` -vscode://vscode-remote/wsl+Ubuntu/path/to/file.php:1 -``` - -Clicking this link in your browser on Windows will open the file in VS Code inside your WSL environment. # PHP Debug Bar [![Latest Stable Version](https://img.shields.io/packagist/v/php-debugbar/php-debugbar?label=Stable)](https://packagist.org/packages/php-debugbar/php-debugbar) [![Total Downloads](https://img.shields.io/packagist/dt/maximebf/debugbar?label=Downloads)](https://packagist.org/packages/php-debugbar/php-debugbar) [![License](https://img.shields.io/badge/Licence-MIT-4d9283)](https://packagist.org/packages/php-debugbar/php-debugbar) [![Tests](https://github.com/maximebf/php-debugbar/actions/workflows/run-tests.yml/badge.svg)](https://github.com/php-debugbar/php-debugbar/actions/workflows/run-tests.yml) diff --git a/docs/vscode_wsl_links.md b/docs/vscode_wsl_links.md new file mode 100644 index 00000000..38898fe5 --- /dev/null +++ b/docs/vscode_wsl_links.md @@ -0,0 +1,35 @@ +# VSCode WSL Remote Xdebug Link Support + +This package now supports generating Xdebug file links for VS Code running in WSL (Windows Subsystem for Linux) via the `vscode-wsl` editor type. + +## Prerequisites + +- Visual Studio Code installed on Windows +- [WSL extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl) for VS Code +- WSL (e.g., Ubuntu) set up on your system + +## Usage + +Set the editor link template to `vscode-wsl`: + +```php +// usage +$collector->setEditorLinkTemplate('vscode-wsl'); +``` + +You can configure the WSL distribution name (e.g., `Ubuntu`) using: + +- The `DEBUGBAR_WSL_NAME` environment variable +- The `setWslName()` method + +If not set, it defaults to `Ubuntu`. + +## Example Link + +The generated link will look like: + +``` +vscode://vscode-remote/wsl+Ubuntu/path/to/file.php:1 +``` + +Clicking this link in your browser on Windows will open the file in VS Code inside your WSL environment.