-
Notifications
You must be signed in to change notification settings - Fork 764
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src/goDebugFactory.ts: run dlv-dap as a server and connect as server
Connect to the dlv dap server directly from vscode, bypassing the thin adapter. This is accomplished using the vscode.DebugAdapterDescriptorFactory for launch configurations of type "godlvdap". Updates #23 Updates #978 Change-Id: I877a1c1b0cf0c40a2ba0602ed1e90a27d8f0159e Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/288954 Trust: Suzy Mueller <[email protected]> Trust: Hyang-Ah Hana Kim <[email protected]> Run-TryBot: Suzy Mueller <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
- Loading branch information
Showing
4 changed files
with
127 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/*--------------------------------------------------------- | ||
* Copyright 2021 The Go Authors. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE in the project root for license information. | ||
*--------------------------------------------------------*/ | ||
|
||
import { ChildProcess } from 'child_process'; | ||
import getPort = require('get-port'); | ||
import { DebugConfiguration } from 'vscode'; | ||
import vscode = require('vscode'); | ||
import { spawnDapServerProcess as spawnDlvDapServerProcess } from './debugAdapter2/goDlvDebug'; | ||
import { logError, logInfo } from './goLogging'; | ||
import { killProcessTree } from './utils/processUtils'; | ||
|
||
export class GoDebugAdapterDescriptorFactory implements vscode.DebugAdapterDescriptorFactory { | ||
|
||
private dlvDapServer?: ChildProcess; | ||
|
||
public async createDebugAdapterDescriptor( | ||
session: vscode.DebugSession, | ||
executable: vscode.DebugAdapterExecutable | undefined | ||
): Promise<vscode.ProviderResult<vscode.DebugAdapterDescriptor>> { | ||
// The dlv-dap server currently receives certain flags and arguments on startup | ||
// and must be started in an appropriate folder for the program to be debugged. | ||
// In order to support this, we kill the current dlv-dap server, and start a | ||
// new one. | ||
await this.terminateDlvDapServerProcess(); | ||
|
||
const {port, host} = await this.startDapServer(session.configuration); | ||
return new vscode.DebugAdapterServer(port, host); | ||
} | ||
|
||
public async dispose() { | ||
await this.terminateDlvDapServerProcess(); | ||
} | ||
|
||
private async terminateDlvDapServerProcess() { | ||
if (this.dlvDapServer) { | ||
await killProcessTree(this.dlvDapServer); | ||
this.dlvDapServer = null; | ||
} | ||
} | ||
|
||
private async startDapServer(configuration: DebugConfiguration): Promise<{ port: number; host: string; }> { | ||
if (!configuration.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(); | ||
} | ||
|
||
this.dlvDapServer = spawnDlvDapServerProcess(configuration, logInfo, logError); | ||
// Wait to give dlv-dap a chance to start before returning. | ||
return await | ||
new Promise<{ port: number; host: string; }>((resolve) => setTimeout(() => { | ||
resolve({port: configuration.port, host: configuration.host}); | ||
}, 500)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters