I know this question might sound similar to this one: How do I add environment variables to launch.json in VSCode
But what I really want is to use the variables from my .env file inside the actual launch.json file, instead of using them in the program.
So my setup is something like this:
project-root/
|-- .env
|-- .vscode/
|-- launch.json
|-- src/
|-- my-plugin/
|-- my-theme/
|-- wordpress/
|-- data/
|-- docker-compose.yml
In my .env file I have this:
PLUGIN_SLUG=my-plugin
THEME_SLUG=my-theme
Now, in my launch.json file, I would really like to be able to use the ${THEME_SLUG}
and ${PLUGIN_SLUG}
variables like this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/var/www/html/wp-content/plugins/${PLUGIN_SLUG}": "${workspaceRoot}/src/${PLUGIN_SLUG}",
"/var/www/html/wp-content/themes/${THEME_SLUG}": "${workspaceRoot}/src/${THEME_SLUG}",
"/var/www/html": "${workspaceRoot}/wordpress",
},
}
],
}
Any idea how to achieve this?
::EDIT::
After digging some further, I realized that when I set the variables globally inside /etc/profile.d/temp.sh
like this:
export PLUGIN_SLUG=codeable-plugin
export THEME_SLUG=codeable-theme
After logging out of my system and back in, I'm able to use these variables anywhere, including in my launch.json file like this:
"/var/www/html/wp-content/plugins/${env:PLUGIN_SLUG}": "${workspaceRoot}/src/${env:PLUGIN_SLUG}",
"/var/www/html/wp-content/themes/${env:THEME_SLUG}": "${workspaceRoot}/src/${env:THEME_SLUG}",
While this is a step closer to what I want, it's not really workable, to update these variables manually in my global OS config each time I switch projects, and then log out and in again.
php
is not a valid type for launch configs. Ultimately, I think you will be at the mercy of extension support on this one sadly. I think your question is specific to php and using an.env
file not just 'using custom env variables', because, for example, usingenvFile
is already supported with node launch configsenvFile
property, enter the file name and to reference the variables you do it like you showed in your example:${env:}
${env:}
is only available for global system variables. I could be wrong though. Did you find any documentation about this?.env
file automatically, correct. That’s what theenvFile
property is for. github.com/microsoft/vscode-js-debug/blob/master/OPTIONS.md