How to know the run command that vscode creates from launch.json? - go

I have a launch.json like below:
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"env": {},
"args": ["server"]
}
]
}
When I launch it using the debug view on VScode it works fine but I need to change the program attribute to relative path of the respective file from my workspace location, strange behaviour is observed, other components in the same package start throwing undefined func error. Probably something goes wrong with current working dir or go module setup.
In order to investigate further, I need to know the command that is generated from this launch.json file. It should be something like go run ...
I have checked the output and debug console, both of them shows nothing about the launch command.
If you know how to see launch command, please help.

You can find the generated command in Visual Studio Code's debug output. When you have started a debug session, open the Debug Console by clicking on the Debug Console icon in the View Bar or by pressing Ctrl + Shift + Y. The debug output will include the generated command line.

Related

How do I launch/debug a project in an external console?

I am trying to debug a Go project in VSCode. I am able to debug it, but the application is running in the internal VSCode terminal. I need the application to run in an external console instead. For instance I want it to run in cmd.exe.
// .vscode/launch.json
{
// 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 Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}"
}
]
}
How can I make the debug session open a external console and run it there, rather than in the internal console of VSCode?
The developers for the Go VSCode extension are in the process of adding a launch property for this. See: https://github.com/golang/vscode-go/issues/124#issuecomment-1006122877

Disable "Failed to continue: Check debug console" error message in vscode

How do I get rid of this annoying message every time there's an error in my code?
I found the solution to this problem:
The error message isn't actually caused by VScode, it's caused by the golang extension.
To disable it you have to go to the extension manager and click the little gear next to the installed extension and revert it to a previous version from the context menu. The version I reverted to is from about a year ago.
If you don't see the little gear icon you need to have the extension installed first.
Add your main.go file path to "program" attribute located in launch.json file.
{
// 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": "E:/GoProjects/main.go",
"env": {},
"args": []
}
]
}
Check the Go Lang extension settings and turn off the "Build On Save" feature.

Finding gitlab.com/company/project/.vscode latest

I'm trying to debug a go project with vscode, when I run debug with those settings:
{
// 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}",
"envFile": "${workspaceFolder}/.env.local",
"args": [],
}
]
}
I get:
go: finding gitlab.com/company/project/.vscode latest
can't load package: package gitlab.com/company/project/.vscode: unknown import path "gitlab.com/company/project/.vscode": cannot find module providing package gitlab.com/company/project/.vscode
exit status 1
Process exiting with code: 1
What can I do to fix it ?
Sounds like you're editing a file within your .vscode folder (e.g. the launch.json file you quoted) when you try to debug. Debug is relative to the file you have open (as you can see by the ${fileDirname} in your config). So the easiest fix is to make sure you have open the Go file you want to debug when you try to debug.
If you only ever want to debug one binary in your project, you can override the program setting in launch.json to always point at that package.

can't debug bash scripts using VSCode

I've installed VSCode with Bash debug extension.
Before that, I've installed bashdb and I've verified its version using (bashdb --version) and it's 4.4.
Now, the extension creates an empty file called launch.json.
I wrote the following to start debugging, but still, nothing happened
{
"version": "0.2.0",
"scriptPath": "${command:SelectScriptName}",
"configurations": [
],
"compounds": [
{
"type": "bashdb",
"name": "Compound",
"configurations": []
}
]
}
What should I do to enable debugging?
Regards,
With the bashdb extension installed, add the following block to the launch.json file. This configuration allows you to debug the script you have currently open on VS Code. So, in order to start debugging a script you must have it open on VS Code, and type F5 to start debugging it. Alternatively, and also with the same script open on VS Code, you can open the Run and Debug menu, on the VS Code left bar, and click Play.
{
"type": "bashdb",
"request": "launch",
"name": "Bash-Debug (simplest configuration)",
"cwd": "${workspaceFolder}",
"program": "${file}",
"showDebugOutput": true,
"terminalKind": "integrated"
}
Adding the args parameter to the above block, allows you to pass an array with arguments to the script while debugging.
I tested this code with the Bash Debug extension:
{
"version": "0.2.0",
"configurations":
[
{
"type": "bashdb",
"request": "launch",
"name": "Bash-Debug (select script from list of sh files)",
"cwd": "${workspaceFolder}",
"program": "${command:SelectScriptName}",
"args": []
}
]
}
Visual Studio Code displays a list of script from your project, and you can pick the one you want to run. You can alternatively choose a "Bash-Debug (hardcoded script name)" configuration, which allow to hardcode the script path.
If you want to debug a Bash script I recommend you execute your script with -x flag. For example:
bash -x script.sh
or into the script add:
set -x
<DEBUG_CODE_LINES>
set +x

Is there way to open DEBUG CONSOLE tab after starting debugging with specified preLaunchTask?

I have debug configuration with preLaunchTask:
{
"type": "node",
"request": "launch",
"name": "index.js - Build then launch",
"program": "${workspaceRoot}/node/dist/index.js",
"cwd": "${workspaceRoot}/node",
"preLaunchTask": "build"
}
And when I start debugging, vscode opens OUTPUT tab instead of DEBUG CONSOLE:
Is there way to open DEBUG CONSOLE after starting debugging? I wanted to create extension with interact with DOM UI, but it turned out that extensions dont have access to DOM UI.
You can set "internalConsoleOptions": "openOnSessionStart" in your launch config to always show the console after starting a debug session.
"internalConsoleOptions": "openOnSessionStart" is not sufficient for python launch configs.
It also requires
"purpose": [
"debug-test"
],
launch.json
{
// 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": "Python: Debug Tests",
"type": "python",
"request": "launch",
"program": "${file}",
"purpose": [ //
"debug-test"
],
"console": "integratedTerminal",
"justMyCode": false,
"internalConsoleOptions": "openOnSessionStart"
}
]
}
Is there way to open DEBUG CONSOLE after starting debugging?
As another alternative, VSCode 1.70 (July 2022) offers:
Changing Quick Access for Debug Consoles to Debug Sessions
Quick access menu for debug consoles just lists your debug consoles, but the view menu pretty much lists the same.
Before: Quick access for debug consoles:
VScode 1.70: The quick access should actually just list the debug sessions like the call stack does.
See PR 153727, released today in VSCode insiders.
This can be accessed with the command Select Debug Session
It would look like this (but as a regular quickpick, not a quick access anymore):
for this tree structure:
Or for something different like python (where there are no compact debug sessions):
tree structure:
The structure is pretty generic to support any type of debug session.

Resources