Skip to content

Commit

Permalink
src/goDebugFactory: don't modify DebugConfiguration.port
Browse files Browse the repository at this point in the history
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 <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
  • Loading branch information
hyangah committed Mar 29, 2021
1 parent 4d9d401 commit d04ba21
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/goDebugFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,29 +244,28 @@ export async function startDapServer(
log?: (msg: string) => void,
logErr?: (msg: string) => void
): Promise<{ port: number; host: string; dlvDapServer?: ChildProcessWithoutNullStreams }> {
if (!configuration.host) {
configuration.host = '127.0.0.1';
}
const host = configuration.host || '127.0.0.1';

if (configuration.port) {
// If a port has been specified, assume there is an already
// running dap server to connect to.
return { port: configuration.port, host: configuration.host };
} else {
configuration.port = await getPort();
return { port: configuration.port, host };
}
const port = await getPort();
if (!log) {
log = appendToDebugConsole;
}
if (!logErr) {
logErr = appendToDebugConsole;
}
const dlvDapServer = await spawnDlvDapServerProcess(configuration, log, logErr);
return { dlvDapServer, port: configuration.port, host: configuration.host };
const dlvDapServer = await spawnDlvDapServerProcess(configuration, host, port, log, logErr);
return { dlvDapServer, port, host };
}

async function spawnDlvDapServerProcess(
launchArgs: vscode.DebugConfiguration,
host: string,
port: number,
log: (msg: string) => void,
logErr: (msg: string) => void
): Promise<ChildProcess> {
Expand All @@ -293,7 +292,7 @@ async function spawnDlvDapServerProcess(
if (launchArgs.dlvFlags && launchArgs.dlvFlags.length > 0) {
dlvArgs.push(...launchArgs.dlvFlags);
}
dlvArgs.push(`--listen=${launchArgs.host}:${launchArgs.port}`);
dlvArgs.push(`--listen=${host}:${port}`);
if (launchArgs.showLog) {
dlvArgs.push('--log=' + launchArgs.showLog.toString());
}
Expand Down
1 change: 1 addition & 0 deletions test/integration/goDebug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,7 @@ const testAll = (isDlvDap: boolean) => {
if (isDlvDap) {
const { port, dlvDapServer } = await proxy.startDapServer(debugConfig);
dlvDapProcess = dlvDapServer;
debugConfig.port = port; // let the debug test client connect to our dap server.
await dc.start(port);
}
return debugConfig;
Expand Down

0 comments on commit d04ba21

Please sign in to comment.