Skip to content

Commit

Permalink
src/goDebugConfiguration.ts: replace resolvePath with resolveHomeDir
Browse files Browse the repository at this point in the history
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 #1448

Change-Id: Id5f993f2aa88205b3bdfa986f3b9a020806f97b2
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/312690
Trust: Suzy Mueller <[email protected]>
Run-TryBot: Suzy Mueller <[email protected]>
TryBot-Result: kokoro <[email protected]>
Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
  • Loading branch information
suzmue committed Apr 22, 2021
1 parent ec08530 commit b7797c3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/goDebugConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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'];
Expand Down
33 changes: 33 additions & 0 deletions test/integration/goDebugConfiguration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}');
});
});

0 comments on commit b7797c3

Please sign in to comment.