Launch Debug from Anywhere in Visual Studio Code

Budhi
2 min readJun 15, 2020

Debugging should be easy, except when it’s annoying.

All cereals, no milk.
Photo by Rachael Gorjestani on Unsplash

A debug failing to start in Visual code is up there on my top pet peeves with a piece of celery on your teeth, loud nachos in cinemas and pouring your favorite cereal for breakfast only to have a drop of milk left. Just enough to wet bits of your cereals. Yeeeeargh!

When chasing bugs down the rabbit hole, we may arrive at the innards of code deep in some dark unchartered modules. Satisfied that this obscure line you’ve written half asleep in the wee hours is the source of your frustrations, you click the red debug breakpoint. Then start debug. Then Nothing. Nada. Nought. Zilch. Yeeeeargh!

Visual code error, Failed to Continue.
Debug needs debugging

Naturally, your IDE has no of idea your entry point. Open up launch.json in your .vscode/ directory and modify the configuration to statically point to your main entry point, whatever that may be.

“configurations”: [
{
“name”: “Launch”,
“type”: “go”,
“request”: “launch”,
“mode”: “auto”,
“program”: “${workspaceRoot}/mydir/WhateverFileIWant.go”,
“env”: {},
“args”: []
}
]
Success! Debug started.
Success! Debug started

That’s it. Your debug should start from where you currently are.

TL;DR

Update your launch.json configuration to be able to start debug from anywhere.

Wait, did I just write a medium because I’m too damn lazy to Google this every single time? Yup. Yes I did.

--

--