I am just trying to add some basic configuration to my launch.json file in vscode, but I am getting an error as Property args is not allowed. Below is my configuration.
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "index",
"args": [
"src/index.ts"
],
"cwd": "${workspaceFolder}"
}
],
"compounds": []
}
That was a silly mistake. According to this doc
VS Code debuggers typically support launching a program in debug mode
or attaching to an already running program in debug mode. Depending on
the request (attach or launch) different attributes are required and
VS Code's launch.json validation and suggestions should help with
that.
So when I changed my request to launch from attach, everything was perfect. Only the request type launch supports the configuration args.
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "index",
"args": [
"src/index.ts"
],
"cwd": "${workspaceFolder}"
}
],
"compounds": []
}
Related
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
I'm trying to build files in vscode with an "unsupported" compiler. Therefore I've created a task to start the compiler and this works perfectly, as long as the source and destination files are given. I give my source file as ${file} and vscode correctly substitutes this with the source file. For the destination file I have to use the same filename but change it's extension.
Is it possible for me to create a string variable in .json, copy the value of my ${file} string into that and use change its extension before using it as an argument?
My tasks.json is below, my sourcefile ${file} = "C:\_projects\Customer\Logging\LogAsync\ASyncLog\Server.kl"
{
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": ".\\ktrans.exe",
"problemMatcher": [],
"options": {
"cwd": "C:\\Program Files (x86)\\FANUC\\WinOLPC\\bin\\"
},
"args": [
"${file}",
"C:\\_projects\\Customer\\Logging\\LogAsync\\ASyncLog\\Server.pc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Thanks all for helping. My working code is below for other peaple who came here searching for how to compile Fanuc Karel in vscode:
{
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": ".\\ktrans.exe",
"problemMatcher": [],
"options": {
"cwd": "C:\\Program Files (x86)\\FANUC\\WinOLPC\\bin\\"
},
"args": [
"${file}",
"${fileDirname}\\${fileBasenameNoExtension}.pc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Yes, you can use ${file} to generate an output "arg" for a task in vscode. To do so, simply add the following line to your tasks.json file:
"args": ["${file}"]
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"],
}]
}
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"
]
}
]
}
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