How to compile multiple go files in vscode launch.json?

Issue

If I have several go files that need to be in the main package, how can I specify them to be compiled in the launch.json? I would refactor them into packages. But this project is resisting.

i.e. To run them on the command line, I have to use:

go run main.go stuff.go other.go

How would I include that in the launch.json file?

{
    "name": "Launch myprog",
    "type": "go",
    "request": "launch",
    "mode": "debug",
    "program": "${workspaceRoot}/cmd/myprog/main.go",
     "args": ["param"]
},

I’ve tried the obvious ways. I would like to do some debugging.

So… How do I specify in launch.json to compile the package in the folder and not just one specific file?

If go run main.go is equivalent to "program": "${workspaceRoot}/cmd/myprog/main.go"

Then, go run . is equivalent to what? "program": "${workspaceRoot}/cmd/myprog/[?????]"

Because the obvious didn’t work for me.

Thanks

Solution

There must have been some other problem with my system. Because at some point it all just started working… Though I am also now using the nightly version of the plugin golang.go-nightly. It fixed the missing root debug feature beautifully…

This now works fine…

{
   "name": "Prog",
   "type": "go",
   "request": "launch",
   "mode": "debug",
   "program": "${workspaceRoot}/src/cmd/prog/",
   "args": [""]
},

Answered By – PrecisionPete

Answer Checked By – Robin (GoLangFix Admin)

Leave a Reply

Your email address will not be published.