Skip to content

Commit

Permalink
src/debugAdapter2: launch as an external process, and fix config
Browse files Browse the repository at this point in the history
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 <polina@google.com>
  • Loading branch information
hyangah committed Aug 5, 2020
1 parent c3f97ff commit f9c0454
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
6 changes: 0 additions & 6 deletions src/debugAdapter2/goDlvDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,6 @@ interface AttachRequestArguments extends DebugProtocol.AttachRequestArguments {
showGlobalVariables?: boolean;
}

process.on('uncaughtException', (err: any) => {
const errMessage = err && (err.stack || err.message);
logger.error(`Unhandled error in debug adapter: ${errMessage}`);
throw err;
});

function logArgsToString(args: any[]): string {
return args
.map((arg) => {
Expand Down
12 changes: 12 additions & 0 deletions src/debugAdapter2/goDlvDebugMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@

// This file is for running the godlvdap debug adapter as a standalone program
// in a separate process (e.g. when working in --server mode).
//
// NOTE: we must not include this file when we switch to the inline debug adapter
// launch mode. This installs a process-wide uncaughtException handler
// which can result in the extension host crash.

import { logger } from 'vscode-debugadapter';
import { GoDlvDapDebugSession } from './goDlvDebug';

process.on('uncaughtException', (err: any) => {
const errMessage = err && (err.stack || err.message);
logger.error(`Unhandled error in debug adapter: ${errMessage}`);
throw err;
});

GoDlvDapDebugSession.run(GoDlvDapDebugSession);
10 changes: 8 additions & 2 deletions src/goDebugConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ import { getFromGlobalState, updateGlobalState } from './stateUtils';
import { getBinPath, getCurrentGoPath, getGoConfig } from './util';

export class GoDebugConfigurationProvider implements vscode.DebugConfigurationProvider {
constructor(private defaultDebugAdapterType: string = 'go') { }

public provideDebugConfigurations(
folder: vscode.WorkspaceFolder | undefined,
token?: vscode.CancellationToken
): vscode.DebugConfiguration[] {
return [
{
name: 'Launch',
type: 'go',
type: this.defaultDebugAdapterType,
request: 'launch',
mode: 'auto',
program: '${fileDirname}',
Expand All @@ -45,13 +47,17 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr

debugConfiguration = Object.assign(debugConfiguration || {}, {
name: 'Launch',
type: 'go',
type: this.defaultDebugAdapterType,
request: 'launch',
mode: 'auto',
program: path.dirname(activeEditor.document.fileName) // matches ${fileDirname}
});
}

if (!debugConfiguration.type) {
debugConfiguration['type'] = this.defaultDebugAdapterType;
}

debugConfiguration['packagePathToGoModPathMap'] = packagePathToGoModPathMap;

const gopath = getCurrentGoPath(folder ? folder.uri : undefined);
Expand Down
19 changes: 2 additions & 17 deletions src/goMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,9 @@ export function activate(ctx: vscode.ExtensionContext) {

// debug
ctx.subscriptions.push(
vscode.debug.registerDebugConfigurationProvider('go', new GoDebugConfigurationProvider()));
vscode.debug.registerDebugConfigurationProvider('go', new GoDebugConfigurationProvider('go')));
ctx.subscriptions.push(
vscode.debug.registerDebugConfigurationProvider('godlvdap', new GoDebugConfigurationProvider()));

// Use an InlineDebugAdapterFactory to create a new debug adapter for
// the 'godlvdap' command in inline mode, without launching a subprocess.
const factory = new InlineDebugAdapterFactory();
ctx.subscriptions.push(vscode.debug.registerDebugAdapterDescriptorFactory('godlvdap', factory));
if ('dispose' in factory) {
ctx.subscriptions.push(factory);
}
vscode.debug.registerDebugConfigurationProvider('godlvdap', new GoDebugConfigurationProvider('godlvdap')));

buildDiagnosticCollection = vscode.languages.createDiagnosticCollection('go');
ctx.subscriptions.push(buildDiagnosticCollection);
Expand Down Expand Up @@ -562,13 +554,6 @@ function checkToolExists(tool: string) {
}
}

class InlineDebugAdapterFactory implements vscode.DebugAdapterDescriptorFactory {
public createDebugAdapterDescriptor(session: vscode.DebugSession
): vscode.ProviderResult<vscode.DebugAdapterDescriptor> {
return new vscode.DebugAdapterInlineImplementation(new GoDlvDapDebugSession());
}
}

async function suggestUpdates(ctx: vscode.ExtensionContext) {
const updateToolsCmdText = 'Update tools';
interface GoInfo {
Expand Down

0 comments on commit f9c0454

Please sign in to comment.