Visual Studio Code - Open new window instead of new tab during debugging - visual-studio-code

Is there a way to for VS Code to open a new window in Chrome instead of using existing Chrome window and opening a new tab? (I want each debug session to start off with a clean HttpContext.Session).
Here is my launch.json:
{
"name": "Development",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/net7.0/Nexgen.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
},
"launchSettingsProfile": "Development"
}
I've tried the following, without any success:
Adding a "args": [ "--new-window" ] setting to my launch.json file.
Adding a new task to 'startChrome' and calling it and 'build'. It did launch a new Chrome window, but the debugger still attached to/launched in the previously running browser.
{
"label": "startChrome",
"type": "process",
"command": "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",
"args": [
"--new-window",
"http://localhost:5000"
],
"problemMatcher": []
}
Adding a "commandLineArgs": "--new-instance http://localhost:7058", to my launchSettings.json file.

Solved this by setting serverReadyAction.action = debugWithChrome in launch.json.

Related

VSCode focus on integratedTerminal after hit F5

It's possible to configure launch.json to move focus to integrated terminal after it shows up?
I've configured profile at launch to use the integrated terminal and to not open the debugger console. In below, the current config.
Today I hit “Ctrl+`” right after the terminal starts to focus on it. I want to eliminated that step and make it goes automatically.
{
"name": "Console GerencialISP.Comercial",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "buildComercial",
"program": "${workspaceFolder}/GerencialISP.Comercial/bin/Debug/net6.0/GerencialISP.Comercial.dll",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"args": [],
"cwd": "${workspaceFolder}/GerencialISP.Comercial",
"stopAtEntry": false,
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},

White window when debugging Electron forge "typescript + webpack" app from VSCode - MAIN_WINDOW_WEBPACK_ENTRY variable is not being set

I created an Electron forge project as described in the forge guide using the "typescript + webpack" template:
> yarn create electron-app debugging-test --template=typescript-webpack
The generated app works fine when running npm start. Then I wanted to configure VSCode debugger for this template so I followed the debugging section of the forge guide and created launch.json file with this content:
{
"type": "node",
"request": "launch",
"name": "Electron Main",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron-forge-vscode-nix",
"windows": {
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron-forge-vscode-win.cmd"
},
// runtimeArgs will be passed directly to your Electron application
"runtimeArgs": [
"foo",
"bar"
],
"cwd": "${workspaceFolder}"
}
This does not really work for me. After clicking F5 the debugger starts but it doesn't break on any breakpoints in the main process nor no window appears. Then I tried the launch.json from Microsoft's vscode-recipes:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Electron: Main",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
"runtimeArgs": [
"--remote-debugging-port=9223",
"."
],
"windows": {
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
}
},
{
"name": "Electron: Renderer",
"type": "chrome",
"request": "attach",
"port": 9223,
"webRoot": "${workspaceFolder}",
"timeout": 30000
}
],
"compounds": [
{
"name": "Electron: All",
"configurations": [
"Electron: Main",
"Electron: Renderer"
]
}
]
}
This one, after hitting F5, starts the Electron window fine and even breakpoints in the main process are hit but no content is loaded to the window. The window is white. When breaking on line 21 in index.ts:
mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);
I see that the MAIN_WINDOW_WEBPACK_ENTRY variable is not set and that's why there is no content loaded to the window.
What's the correct VSCode setup to debug "typescript + webpack" electron's forge template?
I found this is a bug in Windows that is tracked here on Github. The workaround is to remove the fork-ts-checker-webpack-plugin. E.g., in webpack.plugins.js remove the new ForkTsCheckerWebpackPlugin() from the array for now until it is fixed:
//const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
module.exports = [/*new ForkTsCheckerWebpackPlugin()*/];
After that debugging both, main and renderer, processes work great!

Debugging Fortran code with gdb under Visual Studio Code in Windows

I saw other posts like this that explain how to debug with gdb. But it still wont work with me. I installed the following extensions:
I created the following launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Run GDB",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\run.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"externalConsole": false,
"MIMode": "gdb",
"preLaunchTask": "compile_with_gfortran"
}
]
}
and the following tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "compile_with_gfortran",
"type": "shell",
"command": "gfortran -o run.exe example.f90 -g",
"options": {
"cwd": "${workspaceFolder}"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Both json files are inside the folder .vscode. By hitting shift-ctrl-B the task builds correctly and creates the executable. When I click F5 to start the compiler, the preLaunchTask runs, the compiling buttons (step in etc...) show up but nothing attaches to the Fortran file, although I added breakpoints into proper locations. And nothing shows up in the debug console. Any suggestion?

How do I make vs code put the output of my c program in TERMINAL panel?

I'm trying to build and run C code with vscode on windows 10.
I've gone through the vscode doc for mingw configuration, followed the steps there and managed to run a .c file with vscode.
However, there's still an issue yet.
each time run my program via "Run | Run Without Debugging", the panel switches automatically to "TERMINAL"
So I have to switch to the DEBUG CONSOLE manually each time I run the code, which is tediously boring.
Is there a way to keep the "DEBUG CONSOLE" panel active or show the output of my program in "TERMINAL" panel
I also tried the suggestion in another stackoverflow post, but it doesn't work for me.
tasks.json
Here is my tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "E:\\MinGW\\bin\\gcc.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: E:\\MinGW\\bin\\gcc.exe"
}
]
}
launch.json
Here is my 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": "gcc.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "E:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe build active file"
}
]
}
How do I make vs code put the output of my c program in TERMINAL panel?
You can use Code Runner with some simple configuration.
Install Code Runner.
Type Ctrl + Shift + P
Search and open Open Settings(JSON)
Add the following json snippets to your settings.json:
"code-runner.runInTerminal": true
Every time you want to run your c code, just type the icon from the upper right corner that Code Runner provide.
For step 4, you can also open vscode settings and change it on GUI.

Combining two launch.json configurations to run sequentially in Visual Studio Code

As part of a .NET Core 2.0 project I'm starting up a .dll then launching Chrome to debug the front end via the Debugger for Chrome extension.
If I launch both manually as such:
{
"name": "[Development] Launch Server",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/netcoreapp2.0/Website.dll",
"args": [],
"cwd": "${workspaceRoot}",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"env": {
"ASPNETCORE_ENVIRONMENT": "LocalDevelopment"
},
"sourceFileMap": {
"/Views": "${workspaceRoot}/Views"
}
}
and then
{
"name": "[Development] Debug Browser",
"type": "chrome",
"request": "launch",
"url": "http://localhost:5000/home",
"port": 9222,
"webRoot": "${workspaceRoot}",
"sourceMapPathOverrides": {
"webpack:///./*": "${workspaceRoot}\\*"
}
}
everything works great. However, this is a slow process because the 'Launch Server' configuration takes a few minutes to build/release and then I must manually launch 'Debug Browser'.
Ideally I would have a 'one click' solution that handles the first configuration and upon release starts up the second configuration.
I have tried:
"compounds": [
{
"name": "[Development] Launch Server & Debug Browser",
"configurations": [
"[Development] Launch Server",
"[Development] Debug Browser"
]
}
]
but this just ends up launching the first configuration and receiving this error
while the second configuration seemingly never firing off. I've looked into tasks.json but I'm not sure that's the right place for what I'm trying to accomplish.
How can I turn this into a fire and forget?