Skip to content

Commit d04ba21

Browse files
committed
src/goDebugFactory: don't modify DebugConfiguration.port
This is a change to avoid modifying vscode.DebugConfiguration's port attribute inside startDapServer function. VSCode invokes DebugAdapterDescriptorFactory's createDebugAdapterDescriptor with the same DebugSession & DebugConfiguration objects when the session restart is requested. If we mess with the port attribute, the next call will be handled as if it was requested to connect to an external DAP server. So, let's stop modifying it. Updates #1347 Change-Id: I82d7b7f48924fd36e7a881be39fedf2e440e4809 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/305552 Trust: Hyang-Ah Hana Kim <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Suzy Mueller <[email protected]>
1 parent 4d9d401 commit d04ba21

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/goDebugFactory.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,29 +244,28 @@ export async function startDapServer(
244244
log?: (msg: string) => void,
245245
logErr?: (msg: string) => void
246246
): Promise<{ port: number; host: string; dlvDapServer?: ChildProcessWithoutNullStreams }> {
247-
if (!configuration.host) {
248-
configuration.host = '127.0.0.1';
249-
}
247+
const host = configuration.host || '127.0.0.1';
250248

251249
if (configuration.port) {
252250
// If a port has been specified, assume there is an already
253251
// running dap server to connect to.
254-
return { port: configuration.port, host: configuration.host };
255-
} else {
256-
configuration.port = await getPort();
252+
return { port: configuration.port, host };
257253
}
254+
const port = await getPort();
258255
if (!log) {
259256
log = appendToDebugConsole;
260257
}
261258
if (!logErr) {
262259
logErr = appendToDebugConsole;
263260
}
264-
const dlvDapServer = await spawnDlvDapServerProcess(configuration, log, logErr);
265-
return { dlvDapServer, port: configuration.port, host: configuration.host };
261+
const dlvDapServer = await spawnDlvDapServerProcess(configuration, host, port, log, logErr);
262+
return { dlvDapServer, port, host };
266263
}
267264

268265
async function spawnDlvDapServerProcess(
269266
launchArgs: vscode.DebugConfiguration,
267+
host: string,
268+
port: number,
270269
log: (msg: string) => void,
271270
logErr: (msg: string) => void
272271
): Promise<ChildProcess> {
@@ -293,7 +292,7 @@ async function spawnDlvDapServerProcess(
293292
if (launchArgs.dlvFlags && launchArgs.dlvFlags.length > 0) {
294293
dlvArgs.push(...launchArgs.dlvFlags);
295294
}
296-
dlvArgs.push(`--listen=${launchArgs.host}:${launchArgs.port}`);
295+
dlvArgs.push(`--listen=${host}:${port}`);
297296
if (launchArgs.showLog) {
298297
dlvArgs.push('--log=' + launchArgs.showLog.toString());
299298
}

test/integration/goDebug.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,7 @@ const testAll = (isDlvDap: boolean) => {
18071807
if (isDlvDap) {
18081808
const { port, dlvDapServer } = await proxy.startDapServer(debugConfig);
18091809
dlvDapProcess = dlvDapServer;
1810+
debugConfig.port = port; // let the debug test client connect to our dap server.
18101811
await dc.start(port);
18111812
}
18121813
return debugConfig;

0 commit comments

Comments
 (0)