Skip to content

Commit c189ec0

Browse files
committed
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 #1293 Change-Id: Ie0feb5fc2ba40532455726488e3857a8cff2e1a9 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/306969 Trust: Suzy Mueller <[email protected]> Run-TryBot: Suzy Mueller <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
1 parent d5c8951 commit c189ec0

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

docs/settings.md

+2
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,15 @@ Delve settings that applies to all debugging sessions. Debug configuration in th
143143
| Properties | Description |
144144
| --- | --- |
145145
| `apiVersion` | Delve Api Version to use. Default value is 2. <br/> Allowed Options: `1`, `2` <br/> Default: `2` |
146+
| `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"` |
146147
| `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>} ``` |
147148
| `showGlobalVariables` | Boolean value to indicate whether global package variables should be shown in the variables pane or not. <br/> Default: `false` |
148149

149150
Default:
150151
```
151152
{
152153
"apiVersion" : 2,
154+
"debugAdapter" : "legacy",
153155
"dlvLoadConfig" : {
154156
"followPointers" : true,
155157
"maxArrayValues" : 64,

package.json

+11-1
Original file line numberDiff line numberDiff line change
@@ -1700,6 +1700,15 @@
17001700
"type": "boolean",
17011701
"description": "Boolean value to indicate whether global package variables should be shown in the variables pane or not.",
17021702
"default": false
1703+
},
1704+
"debugAdapter": {
1705+
"type": "string",
1706+
"enum": [
1707+
"legacy",
1708+
"dlv-dap"
1709+
],
1710+
"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.",
1711+
"default": "legacy"
17031712
}
17041713
},
17051714
"default": {
@@ -1711,7 +1720,8 @@
17111720
"maxStructFields": -1
17121721
},
17131722
"apiVersion": 2,
1714-
"showGlobalVariables": false
1723+
"showGlobalVariables": false,
1724+
"debugAdapter": "legacy"
17151725
},
17161726
"description": "Delve settings that applies to all debugging sessions. Debug configuration in the launch.json file will override these values.",
17171727
"scope": "resource"

src/goDebugConfiguration.ts

+3
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
196196
// expand 'cwd' folder path containing '~', which would cause dlv to fail
197197
debugConfiguration['cwd'] = resolvePath(debugConfiguration['cwd']);
198198
}
199+
if (!debugConfiguration.hasOwnProperty('debugAdapter') && dlvConfig.hasOwnProperty('debugAdapter')) {
200+
debugConfiguration['debugAdapter'] = dlvConfig['debugAdapter'];
201+
}
199202

200203
// Remove any '--gcflags' entries and show a warning
201204
if (debugConfiguration['buildFlags']) {

src/goTest.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ async function debugTestAtCursor(
196196
name: 'Debug Test',
197197
type: 'go',
198198
request: 'launch',
199-
mode: 'auto',
200-
program: editor.document.fileName,
199+
mode: 'test',
200+
program: path.dirname(editor.document.fileName),
201201
env: goConfig.get('testEnvVars', {}),
202202
envFile: goConfig.get('testEnvFile'),
203203
args,

0 commit comments

Comments
 (0)