5

Trying to use vscode debugger to debug my go code.
vscode runs all the .go files in the same dir using the following launch.json config file:

        {
            "name": "Test",
            "type": "go",
            "request": "launch",
            "mode": "test",
            "program": "${relativeFileDirname}",
        }     

Obviously, I tried to change "program": "${relativeFileDirname}", -> "program": "${file}", but it's not working.
In addition, is there a way I can run ut and not the whole file (or in this case the whole dir)?

1
  • If you are trying to run the debugger for your code and not the tests, the mode parameter should be set to debug and not test. You can take a look at this extensive documentation for setup steps, supported features, configurations, information on remote debugging and a troubleshooting guide: github.com/golang/vscode-go/wiki/debugging Commented Jul 20, 2022 at 6:56

2 Answers 2

12

You can use the following launch.json configuration to run the main.go file in the same directory as .vscode. Change the file name main.go to the corresponding go file to run them

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "some name",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "main.go",
        }
    ]
}
Sign up to request clarification or add additional context in comments.

Comments

2

This one works too :

{
"version": "0.2.0",
"configurations": [

    {
        "name": "Launch Package",
        "type": "go",
        "request": "launch",
        "mode": "auto",
        "program": "${workspaceRoot}"
    }
]

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.