Skip to content

Commit

Permalink
src/goTest.ts: allow users to select default debug adapter
Browse files Browse the repository at this point in the history
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#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]>
  • Loading branch information
suzmue committed Apr 12, 2021
1 parent d5c8951 commit c189ec0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,15 @@ Delve settings that applies to all debugging sessions. Debug configuration in th
| 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` |

Default:
```
{
"apiVersion" : 2,
"debugAdapter" : "legacy",
"dlvLoadConfig" : {
"followPointers" : true,
"maxArrayValues" : 64,
Expand Down
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions src/goDebugConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
// 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']) {
Expand Down
4 changes: 2 additions & 2 deletions src/goTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ async function debugTestAtCursor(
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,
Expand Down

0 comments on commit c189ec0

Please sign in to comment.