src/goTest.ts: allow users to select default debug adapter

Add a configuration to delveConfig, to allow users to select which
debug adapter to use by default (codelenses included). The options
are the same as for launch.json.

Additionally, we take the directory containing the tests instead of
the test file, because 'go test ./file_test.go' does not include
the package which contains './file_test.go', so we should be passing
the package.

Fixes golang/vscode-go#1293

Change-Id: Ie0feb5fc2ba40532455726488e3857a8cff2e1a9
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/306969
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
diff --git a/docs/settings.md b/docs/settings.md
index e255a96..fe1ccd3 100644
--- a/docs/settings.md
+++ b/docs/settings.md
@@ -143,6 +143,7 @@
 | Properties | Description |
 | --- | --- |
 | `apiVersion` | Delve Api Version to use. Default value is 2. <br/> Allowed Options: `1`, `2` <br/> Default: `2` |
+| `debugAdapter` | Select which debug adapter to use by default. This is also used for choosing which debug adapter to use when no launch.json is present and with codelenses. <br/> Allowed Options: `legacy`, `dlv-dap` <br/> Default: `"legacy"` |
 | `dlvLoadConfig` | LoadConfig describes to delve, how to load values from target's memory <br/> Default: ``` { <pre>"followPointers" :	true,<br/>"maxArrayValues" :	64,<br/>"maxStringLen" :	64,<br/>"maxStructFields" :	-1,<br/>"maxVariableRecurse" :	1,</pre>} ``` |
 | `showGlobalVariables` | Boolean value to indicate whether global package variables should be shown in the variables pane or not. <br/> Default: `false` |
 
@@ -150,6 +151,7 @@
 ```
 {
 	"apiVersion" :	2,
+	"debugAdapter" :	"legacy",
 	"dlvLoadConfig" :		{
 		"followPointers" :	true,
 		"maxArrayValues" :	64,
diff --git a/package.json b/package.json
index fc01f7f..54049d6 100644
--- a/package.json
+++ b/package.json
@@ -1700,6 +1700,15 @@
               "type": "boolean",
               "description": "Boolean value to indicate whether global package variables should be shown in the variables pane or not.",
               "default": false
+            },
+            "debugAdapter": {
+              "type": "string",
+              "enum": [
+                "legacy",
+                "dlv-dap"
+              ],
+              "description": "Select which debug adapter to use by default. This is also used for choosing which debug adapter to use when no launch.json is present and with codelenses.",
+              "default": "legacy"
             }
           },
           "default": {
@@ -1711,7 +1720,8 @@
               "maxStructFields": -1
             },
             "apiVersion": 2,
-            "showGlobalVariables": false
+            "showGlobalVariables": false,
+            "debugAdapter": "legacy"
           },
           "description": "Delve settings that applies to all debugging sessions. Debug configuration in the launch.json file will override these values.",
           "scope": "resource"
diff --git a/src/goDebugConfiguration.ts b/src/goDebugConfiguration.ts
index 932cb6b..0adc627 100644
--- a/src/goDebugConfiguration.ts
+++ b/src/goDebugConfiguration.ts
@@ -196,6 +196,9 @@
 			// expand 'cwd' folder path containing '~', which would cause dlv to fail
 			debugConfiguration['cwd'] = resolvePath(debugConfiguration['cwd']);
 		}
+		if (!debugConfiguration.hasOwnProperty('debugAdapter') && dlvConfig.hasOwnProperty('debugAdapter')) {
+			debugConfiguration['debugAdapter'] = dlvConfig['debugAdapter'];
+		}
 
 		// Remove any '--gcflags' entries and show a warning
 		if (debugConfiguration['buildFlags']) {
diff --git a/src/goTest.ts b/src/goTest.ts
index e103391..d1cb29f 100644
--- a/src/goTest.ts
+++ b/src/goTest.ts
@@ -196,8 +196,8 @@
 		name: 'Debug Test',
 		type: 'go',
 		request: 'launch',
-		mode: 'auto',
-		program: editor.document.fileName,
+		mode: 'test',
+		program: path.dirname(editor.document.fileName),
 		env: goConfig.get('testEnvVars', {}),
 		envFile: goConfig.get('testEnvFile'),
 		args,