Skip to content

Commit cfee3e1

Browse files
committed
src/goDebugConfiguration: take program verbatim with external adapter
As a fix for #1677, the extension massages launch configurations to start dlv from the package directory and locate 'program' to be relative from the package directory. This heuristic does not work well if dlv dap adapter is launched externally so dlv runs from other directory. Until `delveCWD` or a similar mechanism that allows to control where delve runs the build, we take the launch configuration verbatim and avoid any mutation. Relative paths are resolved as described in the descriptions in package.json. This changes only the internal mechanics. Fixes #1793 Change-Id: Ic651be25a692dbb23a51707d5ebc274f22a3c532 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/351272 Trust: Hyang-Ah Hana Kim <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Polina Sokolova <[email protected]>
1 parent 022e403 commit cfee3e1

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

src/goDebugConfiguration.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
394394
(attr) => debugConfiguration[attr] && !path.isAbsolute(debugConfiguration[attr])
395395
);
396396
if (debugAdapter === 'dlv-dap') {
397-
// relative paths -> absolute paths
397+
// 1. Relative paths -> absolute paths
398398
if (entriesWithRelativePaths.length > 0) {
399399
const workspaceRoot = folder?.uri.fsPath;
400400
if (workspaceRoot) {
@@ -408,8 +408,18 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
408408
);
409409
}
410410
}
411-
// compute build dir, and translate the dirname in program to a path relative to buildDir.
412-
if (debugConfiguration.request === 'launch') {
411+
// 2. For launch debug/test modes that builds the debug target,
412+
// delve needs to be launched from the right directory (inside the main module of the target).
413+
// Compute the launch dir heuristically, and translate the dirname in program to a path relative to buildDir.
414+
// We skip this step when working with externally launched debug adapter
415+
// because we do not control the adapter's launch process.
416+
if (
417+
debugConfiguration.request === 'launch' &&
418+
// Presence of the following attributes indicates externally launched debug adapter.
419+
!debugConfiguration.port &&
420+
!debugConfiguration.host &&
421+
!debugConfiguration.debugServer
422+
) {
413423
const mode = debugConfiguration['mode'] || 'debug';
414424
if (['debug', 'test', 'auto'].includes(mode)) {
415425
// Massage config to build the target from the package directory

test/integration/goDebugConfiguration.test.ts

+46
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,52 @@ suite('Debug Configuration Converts Relative Paths', () => {
561561
);
562562
});
563563

564+
test('program and __buildDir are not updated when working with externally launched adapters', () => {
565+
const config: vscode.DebugConfiguration = debugConfig('dlv-dap');
566+
config.program = path.join('foo', 'bar', 'pkg');
567+
config.port = 12345;
568+
const workspaceFolder = {
569+
uri: vscode.Uri.file(os.tmpdir()),
570+
name: 'test',
571+
index: 0
572+
};
573+
const { program, cwd, __buildDir } = debugConfigProvider.resolveDebugConfigurationWithSubstitutedVariables(
574+
workspaceFolder,
575+
config
576+
);
577+
assert.deepStrictEqual(
578+
{ program, cwd, __buildDir },
579+
{
580+
program: path.join(os.tmpdir(), 'foo', 'bar', 'pkg'),
581+
cwd: os.tmpdir(),
582+
__buildDir: undefined
583+
}
584+
);
585+
});
586+
587+
test('program and __buildDir are not updated when working with externally launched adapters (debugServer)', () => {
588+
const config: vscode.DebugConfiguration = debugConfig('dlv-dap');
589+
config.program = path.join('foo', 'bar', 'pkg');
590+
config.debugServer = 4777;
591+
const workspaceFolder = {
592+
uri: vscode.Uri.file(os.tmpdir()),
593+
name: 'test',
594+
index: 0
595+
};
596+
const { program, cwd, __buildDir } = debugConfigProvider.resolveDebugConfigurationWithSubstitutedVariables(
597+
workspaceFolder,
598+
config
599+
);
600+
assert.deepStrictEqual(
601+
{ program, cwd, __buildDir },
602+
{
603+
program: path.join(os.tmpdir(), 'foo', 'bar', 'pkg'),
604+
cwd: os.tmpdir(),
605+
__buildDir: undefined
606+
}
607+
);
608+
});
609+
564610
test('empty, undefined paths are not affected', () => {
565611
const config = debugConfig('dlv-dap');
566612
config.program = undefined;

0 commit comments

Comments
 (0)