codelens: a way to use selected launch.json configuration in run test | debug test
- Dominant language
- TypeScript
- Stars
- 4.3k
- Forks
- 929
- PR merge metrics
- No merged PRs in 30d
Description
Users complain that the handy `run test | debug test` links above their test functions ignore the flags they set in their launch configuration ([example](https://github.com/microsoft/vscode-go/issues/2894), [example](https://github.com/go-delve/delve/issues/496#issuecomment-653627364), [example](https://github.com/golang/vscode-go/issues/1450#issuecomment-832409441)). They can fallback on [`settings.json`](https://github.com/golang/vscode-go/blob/master/docs/settings.md) using `go.testFlags`, `go.delveConfig`, etc, but that is not obvious or intuitive and has surprised users with additional limitations for `debug test` vs `run test` (e.g. #1636, https://github.com/microsoft/vscode-go/issues/2894#issuecomment-554303825, https://github.com/microsoft/vscode-go/issues/2115#issuecomment-438137710).
According to @ramya-rao-a, a while back there was no way to feed current selected launch configuration into the codelens, so another set of dlv-related settings was supported as an alternative. Since then a new mechanism to support this could have been introduced, so we should investigate what is possible now.
Below is a quick way to reproduce the current behavior:
Test function:
```
func TestA(t *testing.T) {
log.Println("TestA running")
if !testing.Verbose() {
t.Fatal()
}
}
```
Selected launch configuration
```:
{
"name": "Launch test function",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${workspaceFolder}",
"args": [
"-test.run", "TestA", // no impact with or without on `run/debug test`, which adds its own `-run ^TestA$`
"-test.v"
]
},
```
**Debug with `▷ Start Debugging` or `Run > Start Debugging (F5)`**
Uses `launch.json` configuration, so the test passes.

**Debug with `debug test`**
Doesn't use `launch.json` configuration, so the test fails.

**Run with `Run > Run Without Debugging (^F5)`**
Uses `launch.json` configuration, so the test passes. (Note that this actually goes through the debug adapter, which launches dlv - see #336)

**Run with `run test`**
Doesn't use `launch.json` configuration, so the test fails. (Note that this uses `go test` and bypasses dlv - see #336)

**Adding flags to `settings.json`**
```
"go.testFlags": ["-test.v"]
```
`run test` now passes, but `debug test` behavior is unchanged.
```
"go.testFlags": ["-args","-test.v"]
```
`run test` passes, but only prints "ok", no details. `debug test` works as expected.
```
"go.testFlags": ["-v", "-args","-test.v"]
```
Combining these makes both work as expected - pass and print verbose details.
Contributor guide
Research direction
Start by investigating how the `run test` and `debug test` CodeLens commands resolve launch.json configurations, and compare that with `Start Debugging (F5)` and `Run Without Debugging`. Review the existing `go.testFlags` and `go.delveConfig` settings and the referenced VS Code launch behavior. Done means a selected launch configuration can consistently supply the intended test flags to both CodeLens actions, with coverage for the differing run and debug paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, typescript, vscode
- Domain
- developer-experience, testing, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100