Skip to content

Commit f9c0454

Browse files
committed
src/debugAdapter2: launch as an external process, and fix config
Eventually we want to inline the debug adapter, but until it gets more stable and becomes the default adapter, let's launch it as a separate process to isolate failures. This is handled by the definition in package.json. In order to avoid accidental installation of the process-wide uncaughtException handler when we switch back to the inline mode, move the handler out of goDlvDebug.ts. Also, fixes the default configuration provider for delve dap debug adapter. It should use 'godlvdap' as the type. Fixes #469 Updates #23 Change-Id: I4df2fff51c703995fd557fe5595a367d7048bd7b Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/246777 Reviewed-by: Polina Sokolova <[email protected]>
1 parent c3f97ff commit f9c0454

File tree

4 files changed

+22
-25
lines changed

4 files changed

+22
-25
lines changed

src/debugAdapter2/goDlvDebug.ts

-6
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,6 @@ interface AttachRequestArguments extends DebugProtocol.AttachRequestArguments {
102102
showGlobalVariables?: boolean;
103103
}
104104

105-
process.on('uncaughtException', (err: any) => {
106-
const errMessage = err && (err.stack || err.message);
107-
logger.error(`Unhandled error in debug adapter: ${errMessage}`);
108-
throw err;
109-
});
110-
111105
function logArgsToString(args: any[]): string {
112106
return args
113107
.map((arg) => {

src/debugAdapter2/goDlvDebugMain.ts

+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55

66
// This file is for running the godlvdap debug adapter as a standalone program
77
// in a separate process (e.g. when working in --server mode).
8+
//
9+
// NOTE: we must not include this file when we switch to the inline debug adapter
10+
// launch mode. This installs a process-wide uncaughtException handler
11+
// which can result in the extension host crash.
12+
13+
import { logger } from 'vscode-debugadapter';
814
import { GoDlvDapDebugSession } from './goDlvDebug';
915

16+
process.on('uncaughtException', (err: any) => {
17+
const errMessage = err && (err.stack || err.message);
18+
logger.error(`Unhandled error in debug adapter: ${errMessage}`);
19+
throw err;
20+
});
21+
1022
GoDlvDapDebugSession.run(GoDlvDapDebugSession);

src/goDebugConfiguration.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ import { getFromGlobalState, updateGlobalState } from './stateUtils';
1414
import { getBinPath, getCurrentGoPath, getGoConfig } from './util';
1515

1616
export class GoDebugConfigurationProvider implements vscode.DebugConfigurationProvider {
17+
constructor(private defaultDebugAdapterType: string = 'go') { }
18+
1719
public provideDebugConfigurations(
1820
folder: vscode.WorkspaceFolder | undefined,
1921
token?: vscode.CancellationToken
2022
): vscode.DebugConfiguration[] {
2123
return [
2224
{
2325
name: 'Launch',
24-
type: 'go',
26+
type: this.defaultDebugAdapterType,
2527
request: 'launch',
2628
mode: 'auto',
2729
program: '${fileDirname}',
@@ -45,13 +47,17 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
4547

4648
debugConfiguration = Object.assign(debugConfiguration || {}, {
4749
name: 'Launch',
48-
type: 'go',
50+
type: this.defaultDebugAdapterType,
4951
request: 'launch',
5052
mode: 'auto',
5153
program: path.dirname(activeEditor.document.fileName) // matches ${fileDirname}
5254
});
5355
}
5456

57+
if (!debugConfiguration.type) {
58+
debugConfiguration['type'] = this.defaultDebugAdapterType;
59+
}
60+
5561
debugConfiguration['packagePathToGoModPathMap'] = packagePathToGoModPathMap;
5662

5763
const gopath = getCurrentGoPath(folder ? folder.uri : undefined);

src/goMain.ts

+2-17
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,9 @@ export function activate(ctx: vscode.ExtensionContext) {
118118

119119
// debug
120120
ctx.subscriptions.push(
121-
vscode.debug.registerDebugConfigurationProvider('go', new GoDebugConfigurationProvider()));
121+
vscode.debug.registerDebugConfigurationProvider('go', new GoDebugConfigurationProvider('go')));
122122
ctx.subscriptions.push(
123-
vscode.debug.registerDebugConfigurationProvider('godlvdap', new GoDebugConfigurationProvider()));
124-
125-
// Use an InlineDebugAdapterFactory to create a new debug adapter for
126-
// the 'godlvdap' command in inline mode, without launching a subprocess.
127-
const factory = new InlineDebugAdapterFactory();
128-
ctx.subscriptions.push(vscode.debug.registerDebugAdapterDescriptorFactory('godlvdap', factory));
129-
if ('dispose' in factory) {
130-
ctx.subscriptions.push(factory);
131-
}
123+
vscode.debug.registerDebugConfigurationProvider('godlvdap', new GoDebugConfigurationProvider('godlvdap')));
132124

133125
buildDiagnosticCollection = vscode.languages.createDiagnosticCollection('go');
134126
ctx.subscriptions.push(buildDiagnosticCollection);
@@ -562,13 +554,6 @@ function checkToolExists(tool: string) {
562554
}
563555
}
564556

565-
class InlineDebugAdapterFactory implements vscode.DebugAdapterDescriptorFactory {
566-
public createDebugAdapterDescriptor(session: vscode.DebugSession
567-
): vscode.ProviderResult<vscode.DebugAdapterDescriptor> {
568-
return new vscode.DebugAdapterInlineImplementation(new GoDlvDapDebugSession());
569-
}
570-
}
571-
572557
async function suggestUpdates(ctx: vscode.ExtensionContext) {
573558
const updateToolsCmdText = 'Update tools';
574559
interface GoInfo {

0 commit comments

Comments
 (0)