From b7797c37df0c2b0b4eb019757e5d633f8f657850 Mon Sep 17 00:00:00 2001 From: Suzy Mueller Date: Thu, 22 Apr 2021 13:05:30 -0400 Subject: [PATCH] src/goDebugConfiguration.ts: replace resolvePath with resolveHomeDir Dlv may fail if we pass a cwd containing '~', so when we resolve the debug configuration we resolved '~' using resolvePath. However this also resolved vscode specific information, which vscode would take care of later. Replacing with resolveHomeDir fixes the problem, without modifying the path in any additional way which may lead to unexpected behavior. Fixes golang/vscode-go#1448 Change-Id: Id5f993f2aa88205b3bdfa986f3b9a020806f97b2 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/312690 Trust: Suzy Mueller Run-TryBot: Suzy Mueller TryBot-Result: kokoro Reviewed-by: Hyang-Ah Hana Kim --- src/goDebugConfiguration.ts | 5 +-- test/integration/goDebugConfiguration.test.ts | 33 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/goDebugConfiguration.ts b/src/goDebugConfiguration.ts index c089a2f884..5d2cbaf3b3 100644 --- a/src/goDebugConfiguration.ts +++ b/src/goDebugConfiguration.ts @@ -22,8 +22,9 @@ import { packagePathToGoModPathMap } from './goModules'; import { getTool, getToolAtVersion } from './goTools'; import { pickProcess, pickProcessByName } from './pickProcess'; import { getFromGlobalState, updateGlobalState } from './stateUtils'; -import { getBinPath, getGoVersion, resolvePath } from './util'; +import { getBinPath, getGoVersion } from './util'; import { parseEnvFiles } from './utils/envUtils'; +import { resolveHomeDir } from './utils/pathUtils'; let dlvDAPVersionCurrent = false; @@ -168,7 +169,7 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr } if (debugConfiguration['cwd']) { // expand 'cwd' folder path containing '~', which would cause dlv to fail - debugConfiguration['cwd'] = resolvePath(debugConfiguration['cwd']); + debugConfiguration['cwd'] = resolveHomeDir(debugConfiguration['cwd']); } if (!debugConfiguration.hasOwnProperty('debugAdapter') && dlvConfig.hasOwnProperty('debugAdapter')) { debugConfiguration['debugAdapter'] = dlvConfig['debugAdapter']; diff --git a/test/integration/goDebugConfiguration.test.ts b/test/integration/goDebugConfiguration.test.ts index ab29b5d3cc..804df3b2e5 100644 --- a/test/integration/goDebugConfiguration.test.ts +++ b/test/integration/goDebugConfiguration.test.ts @@ -390,3 +390,36 @@ suite('Debug Configuration Modify User Config', () => { }); }); }); + +suite('Debug Configuration Resolve Paths', () => { + const debugConfigProvider = new GoDebugConfigurationProvider(); + test('resolve ~ in cwd', () => { + const config = { + name: 'Launch', + type: 'go', + request: 'launch', + mode: 'auto', + program: '${fileDirname}', + cwd: '~/main.go' + }; + + debugConfigProvider.resolveDebugConfiguration(undefined, config); + assert.notStrictEqual(config.cwd, '~/main.go'); + }); + + test('do not resolve workspaceFolder or fileDirname', () => { + const config = { + name: 'Launch', + type: 'go', + request: 'launch', + mode: 'auto', + program: '${fileDirname}', + cwd: '${workspaceFolder}' + }; + + debugConfigProvider.resolveDebugConfiguration(undefined, config); + + assert.strictEqual(config.cwd, '${workspaceFolder}'); + assert.strictEqual(config.program, '${fileDirname}'); + }); +});