vscode-php-debug icon indicating copy to clipboard operation
vscode-php-debug copied to clipboard

Support for envFile

Open pwkip opened this issue 5 years ago • 1 comments

It would be nice if we could also include envFile in the launch.json configuration. https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_load-environment-variables-from-external-file-node

Any plans to add this?

Use case:

For example while developing a WordPress website I want to only version my theme and a custom plugin. I have the name of the theme and plugin specified in an .env file:

PLUGIN_DIR=my-custom-plugin
THEME_DIR=mywebsiteslug_theme

Right now I need to hard code the plugin and theme in launch.json like this:

"configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "pathMappings": {
                "/var/www/html/wp-content/plugins/my-custom-plugin": "${workspaceRoot}/src/my-custom-plugin",
                "/var/www/html/wp-content/themes/mywebsiteslug_theme": "${workspaceRoot}/src/mywebsiteslug_theme",
                "/var/www/html": "${workspaceRoot}/wordpress",
            },
        }
],

But it would be nice if I would be able to do this, so I can reuse the same launch.json file for all my projects:

"configurations": [
        {
            "name": "Listen for XDebug",
            "type": "php",
            "request": "launch",
            "port": 9000,
            "envFile": "${workspaceRoot}/.env",
            "pathMappings": {
                "/var/www/html/wp-content/plugins/${env:PLUGIN_DIR}": "${workspaceRoot}/src/${env:PLUGIN_DIR}",
                "/var/www/html/wp-content/themes/${env:THEME_DIR}": "${workspaceRoot}/src/${env:THEME_DIR}",
                "/var/www/html": "${workspaceRoot}/wordpress",
            },
        }
],

pwkip avatar Aug 06 '20 13:08 pwkip

I would do this as a VS Code only change, since the extension infrastructure already has some nice helpers DebugConfigurationProvider / resolveDebugConfigurationWithSubstitutedVariables https://github.com/microsoft/vscode-python/blob/3698950c97982f31bb9dbfc19c4cd8308acda284/src/client/common/variables/environment.ts#L21

zobo avatar May 23 '22 08:05 zobo

I've taken the Node.js debugger as a source and implemented something similar. There the original code: https://github.com/microsoft/vscode-js-debug/blob/766b04bcbb737ad711b50970055eb9782f838c07/src/targets/node/nodeLauncherBase.ts#L275

There is no ${env: substitution in the way you suggested.

First, this is already implemented by VSCode (see https://code.visualstudio.com/docs/editor/variables-reference#_environment-variables) but the editor itself needs to be started in such environment.

I could possible do this with extra work, but this feels like deviating a lot from how other debuggers work...

If you feel strongly about this, let me know and we'll see what I can do.

zobo avatar Aug 30 '22 13:08 zobo