Skip to content

Commit 7ea6b76

Browse files
committed
src/goDebugConfiguration: default to dlv-dap in preview mode
Except when the mode is 'remote'. Moreover, if the mode is 'remote', fall back to 'legacy' mode since that's not a supported operation mode in dlv-dap. Fixes #1539 Fixes #1517 Change-Id: I3df47ae9aafce56a6a8d809b21838cb90f3d03fa Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/325581 Trust: Hyang-Ah Hana Kim <[email protected]> Reviewed-by: Polina Sokolova <[email protected]>
1 parent e7e25d2 commit 7ea6b76

File tree

3 files changed

+85
-15
lines changed

3 files changed

+85
-15
lines changed

src/goDebugConfiguration.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
promptForUpdatingTool,
1919
shouldUpdateTool
2020
} from './goInstallTools';
21+
import { isInPreviewMode } from './goLanguageServer';
2122
import { packagePathToGoModPathMap } from './goModules';
2223
import { getTool, getToolAtVersion } from './goTools';
2324
import { pickProcess, pickProcessByName } from './pickProcess';
@@ -147,8 +148,26 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
147148
// Figure out which debugAdapter is being used first, so we can use this to send warnings
148149
// for properties that don't apply.
149150
if (!debugConfiguration.hasOwnProperty('debugAdapter') && dlvConfig.hasOwnProperty('debugAdapter')) {
150-
debugConfiguration['debugAdapter'] = dlvConfig['debugAdapter'];
151+
const { globalValue, workspaceValue } = goConfig.inspect('delveConfig.debugAdapter');
152+
// user configured the default debug adapter through settings.json.
153+
if (globalValue !== undefined || workspaceValue !== undefined) {
154+
debugConfiguration['debugAdapter'] = dlvConfig['debugAdapter'];
155+
}
156+
}
157+
if (!debugConfiguration['debugAdapter']) {
158+
// for nightly/dev mode, default to dlv-dap.
159+
// TODO(hyangah): when we switch the stable version's default to 'dlv-dap', adjust this.
160+
debugConfiguration['debugAdapter'] =
161+
isInPreviewMode() && debugConfiguration['mode'] !== 'remote' ? 'dlv-dap' : 'legacy';
162+
}
163+
if (debugConfiguration['debugAdapter'] === 'dlv-dap' && debugConfiguration['mode'] === 'remote') {
164+
this.showWarning(
165+
'ignoreDlvDAPInRemoteModeWarning',
166+
"debugAdapter type of 'dlv-dap' with mode 'remote' is unsupported. Fall back to the 'legacy' debugAdapter for 'remote' mode."
167+
);
168+
debugConfiguration['debugAdapter'] = 'legacy';
151169
}
170+
152171
const debugAdapter = debugConfiguration['debugAdapter'] === 'dlv-dap' ? 'dlv-dap' : 'dlv';
153172

154173
let useApiV1 = false;
@@ -270,7 +289,7 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
270289
// file path instead of the currently active file.
271290
filename = debugConfiguration['program'];
272291
}
273-
debugConfiguration['mode'] = filename.endsWith('_test.go') ? 'test' : 'debug';
292+
debugConfiguration['mode'] = filename?.endsWith('_test.go') ? 'test' : 'debug';
274293
}
275294

276295
if (debugConfiguration['mode'] === 'test' && debugConfiguration['program'].endsWith('_test.go')) {

test/integration/goDebug.test.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ const testAll = (ctx: Mocha.Context, isDlvDap: boolean) => {
308308
name: 'Attach',
309309
type: 'go',
310310
request: 'attach',
311-
mode: 'remote',
311+
mode: 'remote', // This implies debugAdapter = legacy.
312312
host: '127.0.0.1',
313313
port: 3456
314314
};
@@ -475,10 +475,9 @@ const testAll = (ctx: Mocha.Context, isDlvDap: boolean) => {
475475
this.skip(); // not working in dlv-dap.
476476
}
477477

478-
if (isDlvDap) {
479-
const config = { name: 'Launch', type: 'go', request: 'launch', program: DATA_ROOT };
480-
await initializeDebugConfig(config);
481-
}
478+
// fake config that will be used to initialize fixtures.
479+
const config = { name: 'Launch', type: 'go', request: 'launch', program: DATA_ROOT };
480+
await initializeDebugConfig(config);
482481

483482
try {
484483
await dc.send('illegal_request');
@@ -491,10 +490,8 @@ const testAll = (ctx: Mocha.Context, isDlvDap: boolean) => {
491490

492491
suite('initialize', () => {
493492
test('should return supported features', async () => {
494-
if (isDlvDap) {
495-
const config = { name: 'Launch', type: 'go', request: 'launch', program: DATA_ROOT };
496-
await initializeDebugConfig(config);
497-
}
493+
const config = { name: 'Launch', type: 'go', request: 'launch', program: DATA_ROOT };
494+
await initializeDebugConfig(config);
498495
await dc.initializeRequest().then((response) => {
499496
response.body = response.body || {};
500497
assert.strictEqual(response.body.supportsConditionalBreakpoints, true);
@@ -511,10 +508,8 @@ const testAll = (ctx: Mocha.Context, isDlvDap: boolean) => {
511508
this.skip(); // not working in dlv-dap.
512509
}
513510

514-
if (isDlvDap) {
515-
const config = { name: 'Launch', type: 'go', request: 'launch', program: DATA_ROOT };
516-
await initializeDebugConfig(config);
517-
}
511+
const config = { name: 'Launch', type: 'go', request: 'launch', program: DATA_ROOT };
512+
await initializeDebugConfig(config);
518513
try {
519514
await dc.initializeRequest({
520515
adapterID: 'mock',
@@ -1993,6 +1988,10 @@ const testAll = (ctx: Mocha.Context, isDlvDap: boolean) => {
19931988
config['logOutput'] = 'dap,debugger';
19941989
config['showLog'] = true;
19951990
config['trace'] = 'verbose';
1991+
} else {
1992+
config['debugAdapter'] = 'legacy';
1993+
// be explicit and prevent resolveDebugConfiguration from picking
1994+
// a default debugAdapter for us.
19961995
}
19971996

19981997
// Give each test a distinct debug binary. If a previous test

test/integration/goDebugConfiguration.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { GoDebugConfigurationProvider } from '../../src/goDebugConfiguration';
1212
import { updateGoVarsFromConfig } from '../../src/goInstallTools';
1313
import { rmdirRecursive } from '../../src/util';
1414
import goEnv = require('../../src/goEnv');
15+
import { isInPreviewMode } from '../../src/goLanguageServer';
1516

1617
suite('Debug Environment Variable Merge Test', () => {
1718
const debugConfigProvider = new GoDebugConfigurationProvider();
@@ -468,3 +469,54 @@ suite('Debug Configuration Auto Mode', () => {
468469
assert.strictEqual(config.program, '/path/to');
469470
});
470471
});
472+
473+
suite('Debug Configuration Default DebugAdapter', () => {
474+
const debugConfigProvider = new GoDebugConfigurationProvider();
475+
test(`default debugAdapter when isInPreviewMode=${isInPreviewMode()} should be 'dlv-dap'`, () => {
476+
const config = {
477+
name: 'Launch',
478+
type: 'go',
479+
request: 'launch',
480+
mode: 'auto',
481+
program: '/path/to/main.go'
482+
};
483+
484+
debugConfigProvider.resolveDebugConfiguration(undefined, config);
485+
const resolvedConfig = config as any;
486+
const want = isInPreviewMode() ? 'dlv-dap' : 'legacy';
487+
assert.strictEqual(resolvedConfig['debugAdapter'], want);
488+
});
489+
490+
test("default debugAdapter for remote mode should be always 'legacy'", () => {
491+
const config = {
492+
name: 'Attach',
493+
type: 'go',
494+
request: 'attach',
495+
mode: 'remote',
496+
program: '/path/to/main_test.go',
497+
cwd: '/path'
498+
};
499+
500+
const want = 'legacy'; // remote mode works only with legacy mode.
501+
debugConfigProvider.resolveDebugConfiguration(undefined, config);
502+
const resolvedConfig = config as any;
503+
assert.strictEqual(resolvedConfig['debugAdapter'], want);
504+
});
505+
506+
test('debugAdapter=dlv-dap should be ignored for remote mode', () => {
507+
const config = {
508+
name: 'Attach',
509+
type: 'go',
510+
request: 'attach',
511+
mode: 'remote',
512+
debugAdapter: 'dlv-dap',
513+
program: '/path/to/main_test.go',
514+
cwd: '/path'
515+
};
516+
517+
const want = 'legacy'; // remote mode works only with legacy mode.
518+
debugConfigProvider.resolveDebugConfiguration(undefined, config);
519+
const resolvedConfig = config as any;
520+
assert.strictEqual(resolvedConfig['debugAdapter'], want);
521+
});
522+
});

0 commit comments

Comments
 (0)