I'm trying to pass the variable "foo" which contains the "bar" in the args field, but no syntax seems to work.
I've tried either for the syntax "${foo}" or "${env:foo}".
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
"env": {
"foo": "bar",
},
"args": [
"${foo}", // output: \$\{foo\}
"${env:foo}" // output: ""
]
},
],
}
Related
I would like to use the output of running which brownie as the value for "program" in a launch.json. E.g. in this snippet of launch.json
"configurations": [
{
"name": "Brownie: run deploy.js",
"type": "python",
"request": "launch",
"program": "/home/fanta/.local/virtualenv/python3.10/bin/brownie",
"console": "integratedTerminal",
"args": ["run", "scripts/deploy.js"]
},
I would like to replace the full path that I have hard-wired /home/fanta/.local/virtualenv/python3.10/bin/brownie with the output of which brownie. How can I do that?
You can setup a preLaunchTask that executes the which brownie and writes it to a temp file
{
"version": "2.0.0",
"tasks": [
{
"label": "which brownie",
"type": "shell",
"command": "which brownie > /tmp/brownie-loc.txt"
}
]
}
Using the extension Command Variable you can use the command extension.commandvariable.file.content to use the file content in the launch
{
"version": "0.2.0",
"configurations": [
{
"name": "Brownie: run deploy.js",
"type": "python",
"request": "launch",
"program": "${input:browniePath}",
"console": "integratedTerminal",
"args": ["run", "scripts/deploy.js"],
"preLaunchTask": "which brownie"
}
],
"inputs": [
{
"id": "browniePath",
"type": "command",
"command": "extension.commandvariable.file.content",
"args": {
"fileName": "/tmp/brownie-loc.txt"
}
}
]
}
In the VSCode's lauch.json file, I use multiple configurations for debugging different files. And some of these variables are common between configurations.
I wonder if this could be possible to define a global variable in the launch.json and use it in different locations of the file?
For example, I'm looking for a way to define variable_common once and use it in config 1 and config 2:
"configurations": [
{
"name": "Python: config 1",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
"args": ["variable_1", "variable_2", "variable_common"]
},
{
"name": "Python: config 2",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
"args": ["variable_3", "variable_4", "variable_common"]
}
]
With the extension Command Variable you can create custom variables
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: config 1",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
"args": ["variable_1", "variable_2", "${input:VAR_COMMON}"]
},
{
"name": "Python: config 2",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true,
"args": ["variable_3", "variable_4", "${input:VAR_COMMON}"]
}
],
"inputs": [
{
"id": "VAR_COMMON",
"type": "command",
"command": "extension.commandvariable.transform",
"args": { "text": "common_arg" }
}
]
}
When trying to start a Debug session in vscode, it throws an error about not finding a specified task. I've already tried the solutions of other SO questions like this but without success.
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": "MSEventHubs_Audit",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/audit-events.py",
"console": "integratedTerminal",
"args": [
"config/config.ini",
],
"envFile": "${workspaceFolder}/.env",
"env": {"PYTHONPATH": "${workspaceRoot}"},
"justMyCode": false,
"preLaunchTask": {
"task": "audit_tunnel"
}
},
{
...
},
]
}
tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"command": "",
"args": [],
"tasks": [
{
"label": "activate_key",
"type": "shell",
"command": "smartOS_card_pin.sh",
"args": [
"${inputs:cardos_pass}"
],
"group": "build",
},
{
"label": "audit_tunnel",
"type": "shell",
"group": "build",
"command": "ssh",
"args": [
"-NL",
"port1:127.0.0.1:port2",
"my_host"
],
"dependsOn": "activate_key"
},
{
...
}
],
"inputs": [
{
"id": "cardos_pass",
"type": "promptString",
"password": true
}
]
}
I've been looking at it for a while and cannot figure out what I'm doing wrong. The proof my task is known by vscode is when the pop-up message appears
I click 'Configure Task', the 'audit_tunnel' appears as an option to edit.
What am I missing?
Change:
"preLaunchTask": {
"task": "audit_tunnel"
}
To:
"preLaunchTask": "audit_tunnel"
I have the following .vscode/launch.json config:
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Next: Chrome",
"url": "localhost:3000",
"webRoot": "${workspaceFolder}/src"
},
{
"type": "node",
"request": "launch",
"name": "Next: Node",
"runtimeExecutable": "${workspaceFolder}/node_modules/next/dist/bin/next",
"port": 9229,
"env": {
"NODE_OPTIONS": "--inspect"
}
}
],
"compounds": [
{
"name": "Next: Full",
"configurations": ["Next: Node", "Next: Chrome"]
}
]
}
By starting debugger with F5, I want it to run the Next: Full command. But instead it runs Next: Chrome, so it may seem like something's not working, but you have to change it manually and re-run:
Then it will work. But is it possible to set it as default within the config?
It is possible by adding additional helpful entry to configurations first in the list, with the same name (type and request are also necessary):
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"name": "Next: Full",
"request": "launch"
},
{
"type": "chrome",
"request": "launch",
"name": "Next: Chrome",
"url": "localhost:3000",
"webRoot": "${workspaceFolder}/src"
},
{
"type": "node",
"request": "launch",
"name": "Next: Node",
"runtimeExecutable": "${workspaceFolder}/node_modules/next/dist/bin/next",
"port": 9229,
"env": {
"NODE_OPTIONS": "--inspect"
}
}
],
"compounds": [
{
"name": "Next: Full",
"configurations": ["Next: Node", "Next: Chrome"]
}
]
}
Which turns out to be working as an alias:
I was trying to set up VSCode to be able to debug Gatsby code.
I am new to Javascript sourcemaps which seem to be the cause of the problem.
I am seeing the following error on launch:
Cannot launch program "c:\Gatsby\myprogram\node_modules\.bin\gatsby" because corresponding Javascript cannot be found.
I verified that the path to the file gatsby in the error exists.
This is the file that I am using for launch.json:
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"protocol": "inspector",
"program": "${workspaceRoot}/node_modules/.bin/gatsby",
"args": ["develop", "-p", "7777"],
"stopOnEntry": false,
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development",
"DEBUG": "gatsby:*"
},
"console": "integratedTerminal",
"sourceMaps": true,
"outFiles": []
}
]
}
I was able to get this working by using globally installed gatsby-cli's gatsby instead of the one in node_modules. So:
npm install --global gatsby-cli
and then (since I use node/npm etc under nvm):
{
"type": "node",
"request": "launch",
"name": "Launch 'gatsby develop'",
"protocol": "inspector",
"program": "${env:HOME}/.nvm/versions/node/v8.11.3/bin/gatsby",
"args": [
"develop"
],
"stopOnEntry": false,
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development",
"DEBUG": "gatsby:*"
},
"console": "integratedTerminal",
"sourceMaps": true,
"outFiles": []
}
worked for me.
I'm on OSX though, more changes may be needed for your Windows setup.
Also: to use node under nvm with VSCode, I used the default alias method from here: Visual Studio Code to use node version specified by NVM
Quoted from the documentation
VS Code Debugger (Auto-Config)
Using VS Code’s integrated terminal run node --nolazy node_modules/.bin/gatsby develop --inspect-brk instead of gatsby develop or node --nolazy --inspect-brk node_modules/.bin/gatsby build instead of gatsby build
VS Code Debugger (Manual Config)
Linux
{
"version": "0.2.0",
"configurations": [
{
"name": "Gatsby develop",
"type": "pwa-node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/.bin/gatsby",
"args": ["develop"],
"env": {
"PARCEL_WORKERS": "0",
"GATSBY_CPU_COUNT": "1",
},
"runtimeArgs": ["--nolazy"],
"console": "integratedTerminal"
},
{
"name": "Gatsby build",
"type": "pwa-node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/.bin/gatsby",
"args": ["build"],
"env": {
"PARCEL_WORKERS": "0",
"GATSBY_CPU_COUNT": "1",
},
"runtimeArgs": ["--nolazy"],
"console": "integratedTerminal"
}
]
}
Windows
{
"version": "0.2.0",
"configurations": [
{
"name": "Gatsby develop",
"type": "pwa-node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/.bin/gatsby",
"windows": {
"program": "${workspaceRoot}/node_modules/gatsby/dist/bin/gatsby"
},
"args": ["develop"],
"env": {
"PARCEL_WORKERS": "0",
"GATSBY_CPU_COUNT": "1",
},
"runtimeArgs": ["--nolazy"],
"console": "integratedTerminal"
},
{
"name": "Gatsby build",
"type": "pwa-node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/.bin/gatsby",
"windows": {
"program": "${workspaceRoot}/node_modules/gatsby/dist/bin/gatsby"
},
"args": ["build"],
"env": {
"PARCEL_WORKERS": "0",
"GATSBY_CPU_COUNT": "1",
},
"runtimeArgs": ["--nolazy"],
"console": "integratedTerminal"
}
]
}