I have a folder, D:\Data\Git\go\src\demo containing one file, main.go. I have installed go1.12.6 windows/amd64. (I am running Windows 10) I am unable to debug the application - the debugger flashes on the screen then disappears ==> nothing happens ==> even though I have set a breakpoint, it does not break into the code for interactive step-through! I can run the app from the commandline ==> go run main.go (current directory is where main.go is located)
My launch.json looks like this:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"env": {},
"args": []
}
]
}
Here is my app:
package main
import "fmt"
func main() {
s := []int{2, 3, 5, 7, 11, 13}
s = s[1:4]
fmt.Println(s)
}
How do I get to debug in VS Code?
Here is the answer:
Ctrl+Shift+P ==> Open Launch.json ==> Save ==> Voila!
(It works. I am now able to step through and debug a simple application with one main.go file in Visual Studio Code)
Note that I have installed all of the dev tools (as per @owlwalks above), as well as dlv (see here: https://github.com/Microsoft/vscode-go/wiki/Debugging-Go-code-using-VS-Code)