Skip to content

Commit 98f2fdc

Browse files
committed
[release] 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]> (cherry picked from commit cfee3e1) Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/351570 Reviewed-by: Robert Findley <[email protected]>
1 parent 890dc19 commit 98f2fdc

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

src/goDebugConfiguration.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
400400
(attr) => debugConfiguration[attr] && !path.isAbsolute(debugConfiguration[attr])
401401
);
402402
if (debugAdapter === 'dlv-dap') {
403-
// relative paths -> absolute paths
403+
// 1. Relative paths -> absolute paths
404404
if (entriesWithRelativePaths.length > 0) {
405405
const workspaceRoot = folder?.uri.fsPath;
406406
if (workspaceRoot) {
@@ -414,8 +414,18 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
414414
);
415415
}
416416
}
417-
// compute build dir, and translate the dirname in program to a path relative to buildDir.
418-
if (debugConfiguration.request === 'launch') {
417+
// 2. For launch debug/test modes that builds the debug target,
418+
// delve needs to be launched from the right directory (inside the main module of the target).
419+
// Compute the launch dir heuristically, and translate the dirname in program to a path relative to buildDir.
420+
// We skip this step when working with externally launched debug adapter
421+
// because we do not control the adapter's launch process.
422+
if (
423+
debugConfiguration.request === 'launch' &&
424+
// Presence of the following attributes indicates externally launched debug adapter.
425+
!debugConfiguration.port &&
426+
!debugConfiguration.host &&
427+
!debugConfiguration.debugServer
428+
) {
419429
const mode = debugConfiguration['mode'] || 'debug';
420430
if (['debug', 'test', 'auto'].includes(mode)) {
421431
// Massage config to build the target from the package directory

test/integration/goDebugConfiguration.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,52 @@ suite('Debug Configuration Converts Relative Paths', () => {
556556
);
557557
});
558558

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

0 commit comments

Comments
 (0)