Skip to content

Commit

Permalink
src/goDebugConfiguration.ts: add resolveDebugConfiguration back
Browse files Browse the repository at this point in the history
https://go-review.googlesource.com/c/vscode-go/+/248659 replaced
resolveDebugConfiguration with resolveDebugConfigurationWithSubstitutedVariables
in order to resolve the envFile correctly in case
the property requires substitution.

I thought, when debug is requested without launch.json, the default
debugConfiguration provided by provideDebugConfiguration would be
used and eventually resolveDebugConfigurationWithSubstitutedVariables
would be called to process it further. However, it doesn't seem that's the case.

Instead, I observed, resolveDebugConfiguration is called first
with an empty debugConfiguration and VS Code just drops the launch
request without calling resolveDebugConfigurationWithSubstitutedVariables
at all.

We still need to implement resolveDebugConfiguration and
let it populate the debugConfiguration.

Fixes #640

Change-Id: I693c19df1a47cb1011cccdd2f582b4cf3c0fc2ab
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/254843
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
  • Loading branch information
hyangah committed Sep 16, 2020
1 parent 9a2bc10 commit 59858d7
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/goDebugConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
];
}

public resolveDebugConfigurationWithSubstitutedVariables(
public resolveDebugConfiguration(
folder: vscode.WorkspaceFolder | undefined,
debugConfiguration: vscode.DebugConfiguration,
token?: vscode.CancellationToken
Expand Down Expand Up @@ -62,9 +62,6 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
debugConfiguration['packagePathToGoModPathMap'] = packagePathToGoModPathMap;

const goConfig = getGoConfig(folder && folder.uri);

combineEnvFilesAndEnv(folder, debugConfiguration);

const dlvConfig = goConfig.get<any>('delveConfig');
let useApiV1 = false;
if (debugConfiguration.hasOwnProperty('useApiV1')) {
Expand Down Expand Up @@ -126,6 +123,26 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
return debugConfiguration;
}

public resolveDebugConfigurationWithSubstitutedVariables(
folder: vscode.WorkspaceFolder | undefined,
debugConfiguration: vscode.DebugConfiguration,
token?: vscode.CancellationToken
): vscode.DebugConfiguration {
// Reads debugConfiguration.envFile and
// combines the environment variables from all the env files and
// debugConfiguration.env, on top of the tools execution environment variables.
// It also unsets 'envFile' from the user-suppled debugConfiguration
// because it is already applied.
const goToolsEnvVars = toolExecutionEnvironment(folder?.uri); // also includes GOPATH: getCurrentGoPath().
const fileEnvs = parseEnvFiles(debugConfiguration['envFile']);
const env = debugConfiguration['env'] || {};

debugConfiguration['env'] = Object.assign(goToolsEnvVars, fileEnvs, env);
debugConfiguration['envFile'] = undefined; // unset, since we already processed.

return debugConfiguration;
}

private showWarning(ignoreWarningKey: string, warningMessage: string) {
const ignoreWarning = getFromGlobalState(ignoreWarningKey);
if (ignoreWarning) {
Expand All @@ -140,18 +157,3 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
});
}
}

// combineEnvFilesAndEnv reads debugConfiguration.envFile and
// combines the environment variables from all the env files and
// debugConfiguration.env, on top of the tools execution environment variables.
// It also unsets 'envFile' from the user-suppled debugConfiguration
// because it is already applied.
function combineEnvFilesAndEnv(
folder: vscode.WorkspaceFolder, debugConfiguration: vscode.DebugConfiguration) {
const goToolsEnvVars = toolExecutionEnvironment(folder?.uri); // also includes GOPATH: getCurrentGoPath().
const fileEnvs = parseEnvFiles(debugConfiguration['envFile']);
const env = debugConfiguration['env'] || {};

debugConfiguration['env'] = Object.assign(goToolsEnvVars, fileEnvs, env);
debugConfiguration['envFile'] = undefined; // unset, since we already processed.
}

0 comments on commit 59858d7

Please sign in to comment.