Running the contributed command:'extension.node-debug.startSession' failed - json

After updating VSCode, I met this issue when I try to debug on macOS:
Running the contributed command:'extension.node-debug.startSession'
failed.
My launch.json is
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${file}",
"outFiles": [
"${workspaceRoot}/out/**/*.js"
]
}
]
}
Following this solution, adding "protocol": "legacy"
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${file}",
"outFiles": [
"${workspaceRoot}/out/**/*.js"
],
"protocol": "legacy"
}
]
}
The error becomes:
Cannot launch program '/app.ts';
setting the 'outFiles' attribute might help.
However, I already have outFiles.
Any other solutions? Thanks

Related

Reference a variabled in tasks.json that was defined in launch.json

I'm trying to configure my project in Visual Studio Code.
I am using CMake+make to build my project. CMake needs to know the project configuration (Debug/Release) and architecture (x64/x86) before it can generate the make files.
I could define 4 tasks and 4 launch configurations to achieve this (each hardcoding both options), but that is a lot of duplication.
Instead, I would like to use environment variables to basically "pass down" the parameters from the launch configuration to a single task.
However, VScode doesn't seem to forward what I define in the launch configuration to the task.
Here is what I have:
// launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug (x64)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/debug/x64/executable",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [
{
"name": "proj_configuration",
"value": "Debug"
},
{
"name": "proj_platform",
"value": "x64"
}
],
// "variables": {
// "proj_configuration": "Debug",
// "proj_platform": "x64"
// },
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "Make Project",
}
]
}
// tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Build Project",
"type": "shell",
"command": "cmake",
"args": [
"-B${workspaceFolder}/build",
"-H${workspaceFolder}",
"-DCMAKE_BUILD_TYPE=${proj_configuration}",
"-DCMAKE_GENERATOR_PLATFORM=${proj_platform}"
],
"group": {
"kind": "build",
"isDefault": false
}
},
{
"label": "Make Project",
"type": "shell",
"command": "make",
"group": {
"kind": "build",
"isDefault": true
},
"dependsOn": ["Build Project"],
}
]
}
When I try to run my project, I get
Executing task: cmake -B/home/user/project/build -H/home/user/project/ -DCMAKE_BUILD_TYPE=${proj_configuration} -DCMAKE_GENERATOR_PLATFORM=${proj_platform}
As you can see, the 2 variables are not replaced.
I've also tried using the property "variables", but no luck using that either.
So, is it possible to do what I described, or do I have to define multiple tasks instead?
with the extension Command Variable you can save a number of strings in a store and use these in launch.json and task.json. See example in the link

How Launch Multiple HTML files in Visual Studio Code?

I am trying to launch HTML multiple files in the same folder, and open them in Chrome (not a new window with every file) in Visual Studio Code. I tried this solution: Multiple Launch Files in Visual Studio Code, but I think, I am missing something.
I always get the message to close my current debug session before starting a new one.
Here is my launch.json file for the folder:
{
// 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": "Chrome1",
"request": "launch",
"type": "pwa-chrome",
"webRoot": "${workspaceFolder}",
"file":"${file}"
},
{
"name": "Chrome2",
"request": "launch",
"type": "pwa-chrome",
"webRoot": "${workspaceFolder}",
"file": "${file}"
},
{
"name": "Chrome3",
"request": "launch",
"type": "pwa-chrome",
"webRoot": "${workspaceFolder}",
"file": "${file}"
}
],
"compounds": [
{
"name": "Chrome1/Chrome2/Chrome3",
"configurations": ["Launch Chrome","Launch Chrome","Launch Chrome"],
"preLaunchTask": "${defaultBuildTask}"
}
]
}
Thanks!
it does open chrome with 3 tab for 3 debug.
{
// 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": [
{
"type": "chrome",
"request": "launch",
"name": "Chrome1",
"file": "${workspaceFolder}/a.html"
}, {
"type": "chrome",
"request": "launch",
"name": "Chrome2",
"file": "${workspaceFolder}/b.html"
}, {
"type": "chrome",
"request": "launch",
"name": "Chrome3",
"file": "${workspaceFolder}/c.html"
}
],
"compounds": [{
"name": "Chrome123",
"configurations": ["Chrome1", "Chrome2", "Chrome3"],
}]
}

Sequential launch in VSCode debugging

Given answered and solved partially regarding this question, I have now the following launch configurations to debug my react-redux + electron app.
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Main",
"program": "${workspaceFolder}/src/main.js",
"protocol": "inspector",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
"runtimeArgs": [
"--remote-debugging-port=9229",
"."
],
"windows": {
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
}
},
{
"type": "node",
"request": "launch",
"name": "NPM",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script",
"start"
],
"port": 9229
},
{
"type": "chrome",
"request": "launch",
"name": "Renderer",
"url": "https://localhost:3000",
"webRoot": "${workspaceFolder}/src",
"runtimeExecutable": "C:/Users/[username]/AppData/Local/Programs/Opera developer/launcher.exe",
"runtimeArgs": [
"--remote-debugging-port=9229"
],
"port": 9229
}
],
"compounds": [
{
"name": "All",
"configurations": [
"Main",
"NPM",
"Renderer"
]
}
]
}
So it works as this: the NPM configuration starts the node.js server and then Renderer and Main respectively debugs the front-end part and back-end part.
However, when the compound setting is launched, all of them are executed at one time and both https://localhost:3000/ and election app shows blank screen until the server is completely set up.
For now, it is okay to just reload the webpage and the electron client once the server starts, but I'm just curious if there is a way to make a sequential-launch order to make it further elegant. Any good ideas?
I think you can make your renderer code a little more elegant by doing an attach instead of a launch.
For example I use a compound where I launch the main, and then attach to the renderer with the following (no reload needed).
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch",
"cwd": "${workspaceRoot}/src/app",
"runtimeExecutable": "${workspaceRoot}/src/app/node_modules/.bin/electron",
"windows": {
"runtimeExecutable": "${workspaceRoot}/src/app/node_modules/.bin/electron.cmd"
},
"runtimeArgs": [
"${workspaceRoot}/src/app",
"--remote-debugging-port=9222"
],
"console": "integratedTerminal",
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/src/app/out/**/*.js",
],
"protocol": "inspector",
},
{
"type": "chrome",
"request": "attach",
"name": "Attach to Renderer",
"trace": true,
"webRoot": "${workspaceRoot}/src/app",
"sourceMaps": true,
"port": 9222,
"timeout": 60000
},
],
"compounds": [
{
"name": "App Main & Renderer",
"configurations": [
"Launch App Main",
"Attach to App Renderer"
]
}
]
}

vs code to run c code

I have an existing code base that builds with a makefile and I'd like to use Visual Studio Code to run it.
There are my launch.json and tasks.json.
{
"version": "0.2.0",
"configurations": [{
"name": "C Launch (GDB)",
"type": "cppdbg",
"request": "launch",
"launchOptionType": "Local",
"targetArchitecture": "x64",
"cwd": "${workspaceRoot}",
"program": "E:/code/c",
"miDebuggerPath": "E:/Program Files/TDM-GCC-64/bin/gdb64.exe",
"args": [""],
"stopAtEntry": false,
"externalConsole": true,
"preLaunchTask": "gcc"  
}]
}
{
"version": "0.1.0",
"command": "gcc",
"args": ["${file}", "-o", "${fileBasenameNoExtension}.exe", "-g3", "-Og", "-Wall", "-static-libgcc", "-std=c11", "-fexec-charset=GBK", "-finput-charset=UTF-8"],
"showOutput": "always",
"problemMatcher": {
"owner": "c",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
then when I run Hello world,then will have some problems.
Try changing your paths to use \ instead of / on Windows. Since you have to escape \ in json strings, the actual value would be:
"program": "E:\\code\\c\\${fileBasenameNoExtension}.exe"
provided the built executable is actually at E:\code\c

Executing a node-webkit application from vscode

I am testing node-webkit in vscode, but I am having issues executing it.
In my launch.json file I have this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "index.html",
"stopOnEntry": false,
"args": [],
"cwd": ".",
"runtimeExecutable": "/home/ryan/nwjs/nw",
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"externalConsole": false,
"sourceMaps": false,
"outDir": null
},
{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 5858
}
]
}
cannot launch program '/home/ryan/Test/index.html'; enabling source maps might help
From the commandline I would run this:
/home/ryan/nwjs/nw /home/ryan/Test
And it runs the application just fine.
So, am I setting this up wrong or something?