From 59858d7848c58fce0eb874a50957eab734c8e296 Mon Sep 17 00:00:00 2001 From: "Hana (Hyang-Ah) Kim" Date: Mon, 14 Sep 2020 20:15:14 -0400 Subject: [PATCH] src/goDebugConfiguration.ts: add resolveDebugConfiguration back 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 golang/vscode-go#640 Change-Id: I693c19df1a47cb1011cccdd2f582b4cf3c0fc2ab Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/254843 Trust: Hyang-Ah Hana Kim Run-TryBot: Hyang-Ah Hana Kim TryBot-Result: kokoro Reviewed-by: Suzy Mueller --- src/goDebugConfiguration.ts | 40 +++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/goDebugConfiguration.ts b/src/goDebugConfiguration.ts index e4528ab0cc..1e3d4e4b46 100644 --- a/src/goDebugConfiguration.ts +++ b/src/goDebugConfiguration.ts @@ -34,7 +34,7 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr ]; } - public resolveDebugConfigurationWithSubstitutedVariables( + public resolveDebugConfiguration( folder: vscode.WorkspaceFolder | undefined, debugConfiguration: vscode.DebugConfiguration, token?: vscode.CancellationToken @@ -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('delveConfig'); let useApiV1 = false; if (debugConfiguration.hasOwnProperty('useApiV1')) { @@ -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) { @@ -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. -}