WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.5k stars 4.2k forks source link

Env: Add ability to specify `xdebug.idekey` for sake of debugging with PhpStorm/IntelliJ #41171

Open westonruter opened 2 years ago

westonruter commented 2 years ago

What problem does this address?

I'm attempting to configure wp-env with Xdebug for PhpStorm/IntelliJ. As I understand, this requires an IDE key for PhpStorm to make the connection with the Debugger. For example, when I have created a server in PhpStorm called amp:

image

I can then run PHPUnit for my plugin with the following command and Xdebug will stop execution at any IDE-specified breakpoints:

wp-env run tests-wordpress 'env PHP_IDE_CONFIG=serverName=amp WORDPRESS_TABLE_PREFIX=wptests_ WP_TESTS_DIR=/var/www/wordpress-develop/tests/phpunit WP_PHPUNIT__TESTS_CONFIG=/var/www/html/phpunit-wp-config.php /var/www/html/wp-content/plugins/amp/vendor/bin/phpunit -c /var/www/html/wp-content/plugins/amp/phpunit.xml.dist

Note the PHP_IDE_CONFIG=serverName=amp environment variable being defined. So that works for the tests environment. However, I'm not having luck with the development environment. I think this is because the xdebug.idekey is undefined in the development instance. The only mention of this configuration I found in the project is https://github.com/WordPress/gutenberg/issues/20636#issuecomment-666335104 but it was hardcoded to VSCODE and it didn't end up getting merged.

For context, see https://github.com/ampproject/amp-wp/pull/6802 for attempting to standardize the AMP plugin development environment to use wp-env.

What is your proposed solution?

There could be a way to specify the xdebug.idekey in the .wp-env file.

westonruter commented 2 years ago

cc @noahtallen

westonruter commented 2 years ago

Well, I was able to get it to work by configuring the PhpStorm server to have the name localhost, and then to set the host as localhost instead of host.docker.internal. So this may not be needed.

noahtallen commented 2 years ago

I remember there was a weird thing with the automatic client detection settings here: https://github.com/WordPress/gutenberg/blob/d5915916abc45e6682f4bdb70888aa41e98aa395/packages/env/lib/init-config.js#L165-L168

It feels a bit weird to make the IDE configurable in .wp-env.json, just because different devs might use different IDEs for the same project. Would it make sense to allow it to be passed in from the environment? E.g. if something is on process.env, add it to the Xdebug settings?

westonruter commented 2 years ago

It feels a bit weird to make the IDE configurable in .wp-env.json, just because different devs might use different IDEs for the same project.

I was thinking perhaps it could be supplied via .wp-env.override.json.

Would it make sense to allow it to be passed in from the environment? E.g. if something is on process.env, add it to the Xdebug settings?

I like that.