How to resolve environment variables in a launch.json configuration?

VS Code will resolve arbitrary environment variables of the form ${env:VAR_NAME} in a launch.json configuration, for example:

{
    "type": "gdb",
    "request": "launch",
    "name": "Debug",
    "program": "${env:TEMP}\\bin\\test.exe"
}

In my Theia setup, this didn’t work out-of-the-box. Is there support for the same kind of environment variable resolving already implemented? If yes, what would be the correct format?

[original thread by David Schafhauser]

It should work out of the box in Theia too.

Are you sure that started Theia process inherits such env variables? How do you start it?

Code is here: https://github.com/eclipse-theia/theia/blob/384176dd46e2265b2753e89d026561a304f2a130/packages/variable-resolver/src/browser/common-variable-contribution.ts#L55-L62

[David Schafhauser]

Huh, quite interesting - Thanks for the hint!

I’ve had a look into the EnvVariablesServerImpl and noticed that variables are always transformed to lowercase on Windows when they are requested:

A quick test revealed that this is indeed the case:

setx UPPER_VAR UPPER_VAR_value
setx lower_var lower_var_value

“program”: “${env:UPPER_VAR}\test.exe” is resolved to \test.exe
“program”: “${env:lower_var}\test.exe” is resolved to lower_var_value\test.exe

This is quite problematic because environment variables in Windows tend to be upper case usually (e.g., PATH, TEMP, APPDATA, …)

I am unsure as to why toLowerCase has been introduced here, maybe you can shed some light on here :slight_smile:
(Also if it helps, I’m running Theia within Electron on a Windows machine)

[David Schafhauser]

The issue seems to be that the look-up is always lowercase, but initially the variables are stored with their actual name which is case-sensitive.

It is a bug, on Windows env are case insensitive, so key gets normalized to resolve the value. The issue is that envs is not populated properly. It should have normalized keys as well.

Please file the issue.

[David Schafhauser]

Done, Thank you: https://github.com/eclipse-theia/theia/issues/7973