Skip to content

Commit 0502351

Browse files
authored
Update envFile variable substitution (#3848)
* Update envFile variable substitution In launch.json, the `envFile` configuration can substitute ${workspaceFolder}, ${workspaceRoot} and ${env::???}. * Fix lint issues
1 parent 5de420e commit 0502351

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Extension/src/Debugger/configurationProvider.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,17 @@ class CppConfigurationProvider implements vscode.DebugConfigurationProvider {
201201

202202
// Add environment variables from .env file
203203
if (config.envFile) {
204+
// replace ${env:???} variables
205+
let envFilePath: string = util.resolveVariables(config.envFile, null);
206+
204207
try {
205-
const parsedFile: ParsedEnvironmentFile = ParsedEnvironmentFile.CreateFromFile(config.envFile.replace(/\${workspaceFolder}/g, folder.uri.path), config["environment"]);
206-
208+
if (folder && folder.uri && folder.uri.fsPath) {
209+
// Try to replace ${workspaceFolder} or ${workspaceRoot}
210+
envFilePath = envFilePath.replace(/(\${workspaceFolder}|\${workspaceRoot})/g, folder.uri.fsPath);
211+
}
212+
213+
const parsedFile: ParsedEnvironmentFile = ParsedEnvironmentFile.CreateFromFile(envFilePath, config["environment"]);
214+
207215
// show error message if single lines cannot get parsed
208216
if (parsedFile.Warning) {
209217
CppConfigurationProvider.showFileWarningAsync(parsedFile.Warning, config.envFile);
@@ -213,7 +221,7 @@ class CppConfigurationProvider implements vscode.DebugConfigurationProvider {
213221

214222
delete config.envFile;
215223
} catch (e) {
216-
throw new Error("Can't parse envFile " + config.envFile);
224+
throw new Error(`Can't parse envFile (${envFilePath}): ${e.message}`);
217225
}
218226
}
219227

0 commit comments

Comments
 (0)