-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix: Add env object syntax to launch.json schema for cppdbg and cppvsdbg
#14691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
aebf397
deb60ac
13f598c
66f6d95
793ac13
146e959
7130385
84a0467
e2b17cf
737ecd1
d961d42
034ed40
30f2f9d
c933aee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -270,6 +270,10 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv | |
| // Add environment variables from .env file | ||
| this.resolveEnvFile(config, folder); | ||
|
|
||
| // Debug adapters consume the legacy `environment` array, not `env`. | ||
| // Convert here so both syntaxes work while preserving `env` precedence. | ||
| this.resolveEnvObject(config); | ||
|
|
||
| await this.expand(config, folder); | ||
|
|
||
| this.resolveSourceFileMapVariables(config); | ||
|
|
@@ -700,6 +704,35 @@ export class DebugConfigurationProvider implements vscode.DebugConfigurationProv | |
| } | ||
| } | ||
|
|
||
| private resolveEnvObject(config: CppDebugConfiguration): void { | ||
| if ((config.type !== DebuggerType.cppdbg && config.type !== DebuggerType.cppvsdbg) || config.request !== 'launch') { | ||
| return; | ||
| } | ||
|
|
||
| const envObject = config.env; | ||
| if (!util.isObject(envObject)) { | ||
| return; | ||
| } | ||
|
|
||
| const environment: Environment[] = util.isArray(config.environment) ? config.environment : []; | ||
| const mergedEnvironment = new Map<string, string>(); | ||
|
|
||
| for (const entry of environment) { | ||
| if (util.isString(entry?.name) && util.isString(entry?.value)) { | ||
| mergedEnvironment.set(entry.name, entry.value); | ||
| } | ||
| } | ||
|
|
||
| for (const [name, value] of Object.entries(envObject)) { | ||
| if (util.isString(value)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✨Copilot (agent117): [Moderate] |
||
| mergedEnvironment.set(name, value); | ||
| } | ||
| } | ||
|
|
||
| config.environment = Array.from(mergedEnvironment.entries()).map(([name, value]) => ({ name, value })); | ||
| delete config.env; | ||
| } | ||
|
|
||
| private resolveSourceFileMapVariables(config: CppDebugConfiguration): void { | ||
| const messages: string[] = []; | ||
| if (config.sourceFileMap) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #include <cstdlib> | ||
| #include <fstream> | ||
|
|
||
| int main(int argc, char *argv[]) { | ||
| if (argc < 3) { | ||
| return 1; | ||
| } | ||
|
|
||
| const char *value = std::getenv(argv[1]); | ||
|
|
||
| std::ofstream resultFile(argv[2]); | ||
| if (!resultFile) { | ||
| return 2; | ||
| } | ||
|
|
||
| if (value) { | ||
| resultFile << value; | ||
| } | ||
|
|
||
| return 0; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.