How to enable race detector for Golang in Visual Studio Code?

Viewed 1640

I searched in many web pages to find what phrase exact should I place in settings.json in VS Code Golang extension (released by Microsoft) to add a build flag (in my case, race detector)?

I added:

"go.buildFlags": ["-race"],

in extension's settings.json but still when debugging, in a function that definitely generates a race condition, the debugging console does not denote something like:

Found 1 data race(s)

which the go compiler usually indicates when executing the same file via

go run -race file.go
2 Answers

adding this line in settings.json

"go.testFlags": ["-race"]

works for me

Maybe it's a little late. But adding "go.testFlags": ["-race"] in the user of settings.json doesn't work for me. And adding "buildFlags": "-race" in configurations of launch.json with "mode" being "test" works well for me.

Related