-
Notifications
You must be signed in to change notification settings - Fork 374
[ xdebug ] Add --experimental-unsafe-ide-integration option in Playground CLI
#2777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ xdebug ] Add --experimental-unsafe-ide-integration option in Playground CLI
#2777
Conversation
--experimental-ide option to set xdebug path mappings--experimental-ide option in Playground CLI
|
Let's support an optional explicit value, e.g. Also, this is the top of my It means we cannot trivially use |
|
XDebug is running even during the Blueprint execution – how cool! Also, that's likely only useful for code developers. Let's set some php.ini option to disable xdebug until WordPress fully boots. |
|
I've been testing and reviewing the code and made some adjustments. The server host an port are now explicitly configured based on CLI's host and port. I've seen PhpStorm report an Xdebug connection but haven't been able to hit any breakpoints yet. |
|
I've been testing with an auto-mounted WordPress dir nested under the Playground repo like: |
|
@adamziel is there any additional step in PhpStorm that I should have to do to tell PhpStorm to be able to hit breakpoints? Or should it just work if you have PhpStorm open and Playground CLI started with Xdebug support? |
|
I typically check "stop on first line" and set breakpoints from there @brandonpayton. And you need to turn on the "accept debug connections" toggle |
|
Or in a few more hours, I forgot my power adapter :-) |
|
That error comes from xdebug, likely something wrong with our path mapping or the default initial breakpoint |
|
I found that github issue in VScode-php-debug : Maybe this could be related to your VSCode or an extension you added? Because I don't have any |
|
I plan to review in the next couple of hours. I also plan to make a few simple automated tests after factoring out IDE-specific bits into functions liks |
|
Yay! Also, when the ide integration is used, let's print something visible to tell the user what's next, e.g. per-IDE instructions, or a link to a new doc page explaining the next steps. Right now we know what to do, but it's not that obvious to a new person. Basically, let's handhold the user until they're in an active breakpoint cc @fellyph |
| // NOTE: PhpStorm quirk: Xdebug only works when the full URL (including port) | ||
| // is provided in `host`. The separate `port` field is ignored or misinterpreted, | ||
| // so we rely solely on host: "host:port". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for following upon on this!
| "PHP": "${input:phpVersion}" | ||
| }, | ||
| "enableDWARF": true | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "Debug PHP-WASM" target may not be working well now, and the "Debug Playground CLI with DWARF symbols" is a bit clunky. But personally, I would like to leave at least the Playground CLI target in our launch.json because it gives me a starting point to customize and debug with DWARF symbols.
| vfsPath: '/', | ||
| }; | ||
|
|
||
| clearXdebugIDEConfig(IDEConfigName, process.cwd()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are going to exit if these operations fail, let's await here.
And if we await here we could switch back to try/catch blocks here if desired. It seems a bit strange to me to mix the await and the explicit promise-chaining styles, but I don't really think it matters either way.
| xml === | ||
| '<?xml version="1.0" encoding="UTF-8"?>\n<project version="4">\n <component name="PhpServers">\n <servers></servers>\n </component>\n</project>' | ||
| ) { | ||
| fs.unlinkSync(phpStormConfigFilePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any harm in leaving the file in place? It doesn't seem safe to assume Playground CLI is the creator of the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess not, but I had in mind that if the remaining file looks like that, it certainly is because we created it in the first place. So we could destroy it. But I have the same feeling as you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. 👍 yeah, I bet it will be true in most cases that an empty config is one created by us, but we can't really prove it without some other evidence. It's possible a user had some other config and then removed it during debugging. (just talking this out, not trying to further explain 😄 )
|
|
||
| const json = jsoncApplyEdits(content, edits); | ||
| if (json === '{\n "configurations": []\n}') { | ||
| fs.unlinkSync(vsCodeConfigFilePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question as above. Should we just leave this file in place to be safe?
Sometimes vscode even auto adds sections to the file when opening various kinds of files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If vscode or phpstorm auto adds sections to the file, this means the file won't have that structure anymore so we won't have to destroy it. But, I still have the same feeling as you.
| '/internal/shared/extensions/xdebug.ini' | ||
| ) | ||
| ) { | ||
| const ideKey = xdebugOptions?.ideKey || 'PLAYGROUNDCLI'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PHPStorm seems to require the IDE key for debug configuration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch
|
Thanks for adding tests, @adamziel! I ended up getting pulled away, was going to write them now, and found there was a conflict with the existing test file. Cool! Will read and see if there is anything to add. |
|
@adamziel and @mho22, thank you for getting this ready today. It looks like this is about ready for merge. I made a couple of minor fixes:
If the tests pass, I think this is ready to merge. |
| "runtimeArgs": [ | ||
| "--inspect-brk", | ||
| "--loader=${workspaceFolder}/packages/nx-extensions/src/executors/built-script/loader.mjs" | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: While restoring the removed launch targets, I ended up formatting the file, so there are some whitespace changes like this.
brandonpayton
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good to go. Thanks, everyone!
|
I'll go ahead and merge this since I'm not aware of any remaining reservations. As a follow-up, I plan to submit a PR to have an initial worker for boot that does not hit Xdebug breakpoints during boot (unless maybe an additional flag is passed). I started this locally but don't remember how far along it is. Will see tomorrow. |
|
🎉 🎉 🎉 ! Thank you @brandonpayton and @adamziel ! What a teamwork ! |
Thank you, @mho22! This was fun! |
…wasm CLI (#2947) ## Motivation for the change, related issues Based on issue #2763 and following pull request #2777 This pull request generates the IDE configuration files inside the developer's IDE. ## Implementation details - It first clears all the configs named `PHP.wasm CLI - Listen for Xdebug` in VSCode and PHPStorm config files. - If `--xdebug` and `--experimental-unsafe-ide-integration` options are present, we add IDE configs in the related configs. - PHPStorm : it adds a new `server` with name `PHP.wasm CLI - Listen for Xdebug` in `.idea/workspace.xml`. - VSCode : it adds a new `configuration` with name `PHP.wasm CLI - Listen for Xdebug` in `.vscode/launch.json`. - Correction of an error in Playground CLI console.logs. - Creation of a new distinct package named `@php-wasm/cli-util` which is integrated into PHP.wasm CLI and Playground CLI with the `xdebug-path-mappings`. Next steps are reported in the [Xdebug Follow-up issue](#2315). ## Testing Instructions (or ideally a Blueprint) CI 🧪 test-php-wasm-cli-util cc @fellyph




Motivation for the change, related issues
Based on issue #2763
The current pain we have when we run a Playground CLI command with Xdebug enabled is the absence of the files located in the VFS in our IDE.
This pull request gives visibility to the VFS files with the help of a
.playground-xdebug-rootsymlink and the generation of path mappings inside the developer's IDE.Only the mounts from inside the current working directory are mapped.
Implementation details
.playground-xdebug-root.playground-xdebug-rootin the current working directory.--xdebugand--experimental-unsafe-ide-integrationoptions are present, we symlink the temporary playground cli directory inside the current working directory.WP Playground CLI - Listen for Xdebugin VSCode and PHPStorm config files.--xdebugand--experimental-unsafe-ide-integrationoptions are present, we add IDE configs and path mappings in the related configs.serverwith nameWP Playground CLI - Listen for Xdebugin.idea/workspace.xml.configurationwith nameWP Playground CLI - Listen for Xdebugin.vscode/launch.json.Next steps are reported in the Xdebug Follow-up issue.
Testing Instructions (or ideally a Blueprint)
Run as follows: