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 golang/vscode-go#469
Updates golang/vscode-go#23

Change-Id: I4df2fff51c703995fd557fe5595a367d7048bd7b
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/246777
Reviewed-by: Polina Sokolova <polina@google.com>
diff --git a/src/debugAdapter2/goDlvDebug.ts b/src/debugAdapter2/goDlvDebug.ts
index e992bd8..e1c5b2f 100644
--- a/src/debugAdapter2/goDlvDebug.ts
+++ b/src/debugAdapter2/goDlvDebug.ts
@@ -102,12 +102,6 @@
 	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) => {
diff --git a/src/debugAdapter2/goDlvDebugMain.ts b/src/debugAdapter2/goDlvDebugMain.ts
index 2d4cdb8..8fc3073 100644
--- a/src/debugAdapter2/goDlvDebugMain.ts
+++ b/src/debugAdapter2/goDlvDebugMain.ts
@@ -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);
diff --git a/src/goDebugConfiguration.ts b/src/goDebugConfiguration.ts
index a69087a..b65b47b 100644
--- a/src/goDebugConfiguration.ts
+++ b/src/goDebugConfiguration.ts
@@ -14,6 +14,8 @@
 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
@@ -21,7 +23,7 @@
 		return [
 			{
 				name: 'Launch',
-				type: 'go',
+				type: this.defaultDebugAdapterType,
 				request: 'launch',
 				mode: 'auto',
 				program: '${fileDirname}',
@@ -45,13 +47,17 @@
 
 			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);
diff --git a/src/goMain.ts b/src/goMain.ts
index 664d459..a5abd27 100644
--- a/src/goMain.ts
+++ b/src/goMain.ts
@@ -118,17 +118,9 @@
 
 	// 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);
@@ -562,13 +554,6 @@
 	}
 }
 
-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 {