I want a few terminals opened when I start vscode. The docs show how to do it.
My .vscode/tasks.json:
{
"label": "create terminals",
"runOptions": { "runOn": "folderOpen", }, // <--- should run task on vscode start (but doesn't)
"dependsOn": [ "foo", "bar" ],
},
{ "label": "foo", "type": "shell", "command": "/bin/zsh", "options": { "cwd": "${workspaceFolder}/foo/", }, "isBackground": true, "problemMatcher": [], "presentation": { "echo": false, "panel": "dedicated", "focus": false, "reveal": "never", "group": "terminals" } },
{ "label": "bar", "type": "shell", "command": "/bin/zsh", "options": { "cwd": "${workspaceFolder}/bar/", }, "isBackground": true, "problemMatcher": [], "presentation": { "echo": false, "panel": "dedicated", "focus": false, "reveal": "never", "group": "terminals" } },
That does not run on vscode start. However it works as expected when I run it manually.
How do I make it run on vscode start?
Seems there is more to it - one must also enable "automatic tasks".
Like this: ctrl + p, "Manage Automatic Tasks in Folder", "Allow Automatic Tasks in Folder".
Apparently this will be exposed as a setting in the next vscode version (1.70)
Related
i'm developing embedded firmware on zephyr RTOS. Zephyr env. works on WSL2. And "Vscode remote client" works in Win10 "Vscode Server" works on Ununtu 22.04.
I use Jlink debbugger for flashing and debugging firmware. I have to use remote debugging because debugger connected to Win10 via USB. So I run the JLink "JLinkRemoteServerCL.exe" in Win10 before flash or debug.
But every time I plug or unplug the USB into the PC JLink Remote Connection disconnects. This is annoying.
My goal is to automatically run "JLinkRemoteServerCL.exe" when I run the flash task and close it after the flash task is complete.
I wrote two task for it and connect the flash task to start "JLinkRemoteServerCL.exe" task with "dependsOn" property. But Flash task doesn't start because when start to "JLinkRemoteServerCL.exe" task, it waits connection and never finish.
I do not know how to kill the "Start Remote Server" task even if i achieve run the "Flash" task.
How can I flash my MCU's with run only 1 task?
{
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"command": "west",
"type": "shell",
"group": "build",
"options": {
"cwd": "${workspaceFolder}"
},
"args": [
"build",
"--pristine",
"-b",
"${input:board}",
"-d",
"builds/build_${input:board}",
"--",
"-DBOARD_ROOT=../Common",
"-DCONF_FILE=prj.conf",
"-DOVERLAY_CONFIG=configs/prj_${input:board}.conf",
"-DDTC_OVERLAY_FILE=boards/${input:board}.overlay"
],
"problemMatcher": [
"$gcc"
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
}
},
{
"label": "Build MCUBOOT",
"command": "west",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}"
},
"args": [
"build",
"$ZEPHYR_BASE/../bootloader/mcuboot/boot/zephyr",
"--pristine",
"-b",
"${input:board}",
"-d",
"builds/build_${input:board}/bootloader/mcuboot",
"--",
"-DBOARD_ROOT=${cwd}/../Common",
"-DOVERLAY_CONFIG=${cwd}/bootloader_configs/prj_mcuboot_${input:board}.conf",
"-DDTC_OVERLAY_FILE=${cwd}/boards/${input:board}.overlay",
"-DCONFIG_BOOT_SIGNATURE_KEY_FILE=\\\"${cwd}/../Common/keys/${input:key}\\\""
],
"problemMatcher": [
"$gcc"
],
"presentation": {
"reveal": "always"
},
},
{
"label": "Flash",
"command": "west",
"type": "shell",
"group": "build",
"options": {
"cwd": "${workspaceFolder}"
},
"args": [
"flash",
"-d",
"builds/build_${input:board}",
"--hex-file",
"builds/build_${input:board}/zephyr/zephyr.bin",
"-r",
"jlink",
"--tool-opt=ip 192.168.0.21"
],
"dependsOn" : "Start JLink Remote Server"
},
{
"label": "Flash with MCUBOOT",
"command": "west",
"type": "shell",
"group": "build",
"options": {
"cwd": "${workspaceFolder}"
},
"args": [
"flash",
"-d",
"builds/build_${input:board}",
"--hex-file",
"builds/build_${input:board}/merged.hex",
"-r",
"jlink",
"--tool-opt=ip 192.168.0.21"
],
"dependsOn" : "Start JLink Remote Server"
},
{
"label": "Sign",
"command": "west",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}"
},
"args": [
"sign",
"-t",
"imgtool",
"-d",
"builds/build_${input:board}",
"--",
"--version",
"${input:version_num}",
"--key",
"${workspaceFolder}/../Common/keys/${input:key}"
]
},
{
"label": "Build With MCUBOOT",
"command": "python3",
"type": "shell",
"group": "build",
"args": [
"$ZEPHYR_BASE/scripts/build/mergehex.py",
"builds/build_${input:board}/zephyr/zephyr.signed.hex",
"builds/build_${input:board}/bootloader/mcuboot/zephyr/zephyr.hex",
"-o",
"builds/build_${input:board}/merged.hex"
],
"dependsOn":["Get Inputs", "Build", "Build MCUBOOT", "Sign"],
"dependsOrder": "sequence"
},
{
"label": "Start JLink Remote Server",
"type": "shell",
"command": "/mnt/c/Program\\ Files/SEGGER/JLink/JLinkRemoteServerCL.exe",
},
{
"label": "Get Inputs",
"type": "shell",
"command": "echo",
"args": [
"Board:",
"\b${input:board}",
"Key:",
"\b${input:key}",
"Version:",
"\b${input:version_num}"
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": true
}
}
],
"inputs": [
{
"id": "board",
"description": "Zephyr Target Board",
"default": "witag_litum",
"type": "pickString",
"options":[
"witag_litum",
"nucleo_l073rz",
"witag_bdcip",
"witag",
"tsg001",
"ft06dch",
"eagleeyesense",
"lowcost",
"nrf52833dk_nrf52833",
"nrf52840dongle_nrf52840",
]
},
{
"id": "version_num",
"description": "Version Number:",
"default": "100.100.1+0",
"type": "promptString"
},
{
"id": "key",
"description": "MCUBOOT KEY file located in Common/keys",
"default": "witag_litum",
"type": "pickString",
"options":[
"WiTag.pem",
"WiTag_Litum.pem",
"root-rsa-2048.pem"
]
}
]
}
The closest to my issue is this SO question, but I think something else is going on here. I have two launch configurations each which call a similar preLaunch task, start-local and start-dev. The body of these two tasks is almost identical, except that VS Code can only find whichever of these is declared last in the task.json file. I tested this by duplicating the first task and simply changing the label, and none but the last task can ever be found. Is this a bug or am I doing something wrong? Pasting my configs for reference:
VS Code Version: 1.72.2
OS Version: MacOS 12.6
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Start Dev",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}",
"preLaunchTask": "start-dev",
"postDebugTask": "Terminate All Tasks"
},
{
"name": "Start Local",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3001",
"webRoot": "${workspaceFolder}",
"preLaunchTask": "start-local",
"postDebugTask": "Terminate All Tasks"
},
]
}
task.json
{
"version": "2.0.0",
"tasks": [
{
"label": "start-local",
"type": "npm",
"script": "start",
"isBackground": true,
"problemMatcher": {
"owner": "npm",
"background": {
"activeOnStart": true,
"beginsPattern": ".*",
"endsPattern": "To ignore, add.*eslint-disable-next-line to the line before.*"
},
"pattern": {
"regexp": ""
}
},
"dependsOrder": "sequence",
"dependsOn": [
"setup-local-env"
]
},
{
"label": "setup-local-env",
"command": "echo REACT_APP_STAGE=local > ./.env; echo BROWSER=none >> ./.env",
"type": "shell",
"presentation": {
"echo": false,
"reveal": "never",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false,
"close": true
}
},
{
"label": "start-dev",
"type": "npm",
"script": "start",
"isBackground": true,
"problemMatcher": {
"owner": "npm",
"background": {
"activeOnStart": true,
"beginsPattern": ".*",
"endsPattern": "To ignore, add.*eslint-disable-next-line to the line before.*"
},
"pattern": {
"regexp": ""
}
},
"dependsOrder": "sequence",
"dependsOn": [
"setup-dev-env"
]
},
{
"label": "setup-dev-env",
"command": "echo REACT_APP_STAGE=dev > ./.env; echo BROWSER=none >> ./.env",
"type": "shell",
"presentation": {
"echo": false,
"reveal": "never",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false,
"close": true
}
},
{
"label": "Terminate All Tasks",
"command": "echo ${input:terminate}",
"type": "shell",
"problemMatcher": []
},
],
"inputs": [
{
"id": "terminate",
"type": "command",
"command": "workbench.action.tasks.terminate",
"args": "terminateAll"
}
]
}
I'm working with esp-idf in VS Code. In order to work with esp-idf you have first to import env. variables to your teminal and them be able to call build and flash functions. The question is how to do it properly with the help of Tasks in VS Code. So first I want to prepare the terminal, then build and run. When I manually open the temrinal and execute these commands everything works properly.
{
"version": "2.0.0",
"tasks": [
{
"label": "Prepare",
"type": "shell",
"command": "%IDF_PATH%\\export.bat",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"panel": "shared",
"reveal": "always",
"focus": true
},
"problemMatcher": []
},
{
"label": "Build",
"type": "shell",
"command": "idf.py build",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"panel": "shared",
"reveal": "always",
"focus": true
},
"problemMatcher": []
},
{
"label": "Run monitor",
"type": "process",
"command": "idf.py -p COM4 flash monitor",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"panel": "shared",
"reveal": "always",
"focus": true
},
"problemMatcher": []
}
]
}
I currently have a tasks.json that runs 3 tasks together, grouped in a panel on folder startup:
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Run dev",
"type": "shell",
"command": "npm run dev",
"presentation": {
"reveal": "always",
"panel": "new",
"group": "develop",
},
"runOptions": { "runOn": "folderOpen" }
},
{
"label": "Run css",
"type": "shell",
"command": "npm run watch:css",
"presentation": {
"reveal": "always",
"panel": "new",
"group": "develop",
},
"runOptions": { "runOn": "folderOpen" }
},
{
"label": "Run tunnel",
"type": "shell",
"command": "npm run tunnel",
"presentation": {
"reveal": "always",
"panel": "new",
"group": "develop",
},
"runOptions": { "runOn": "folderOpen" }
},
{
"label": "Start Dev",
"dependsOn": [
"Run dev",
"Run css",
"Run tunnel"
],
"problemMatcher": []
}
]
}
What i'm looking to do is move Run dev to a launch configuration instead so I have debugging enabled by default, and keep the same terminal experience:
launch.json
{
"configurations": [
{
"name": "Run npm run dev",
"command": "npm run dev",
"request": "launch",
"type": "node-terminal",
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"serverReadyAction": {
"pattern": "started at http://localhost:([0-9]+)",
"uriFormat": "http://localhost:%s",
"action": "openExternally"
}
}
]
}
So the end result will be the same 3 tasks, but "Run dev" triggers the "Run npm run dev" launch configuration in it's terminal window
The problem is there doesn't seem to be a way to do this?
This is my tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "Serve API",
"type": "shell",
"command": "yarn nx run api:serve",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "dedicated",
"showReuseMessage": true,
"clear": true
},
"runOptions": {
"runOn": "default"
},
"problemMatcher": []
},
{
"label": "Serve Client",
"type": "shell",
"command": "yarn nx run client:serve",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "dedicated",
"showReuseMessage": true,
"clear": true
},
"runOptions": {
"runOn": "default"
},
"problemMatcher": []
},
{
"label": "Serve API & Client",
"dependsOn": [
"Serve API",
"Serve Client"
],
"runOptions": {
"runOn": "folderOpen"
},
"problemMatcher": []
}
]
}
The last task has no problem auto-starting normally, but doesn't auto-start when in a dev container. I have run the Allow Automatic Tasks in Folder command multiple times to no avail. Is there a setting I can set to permanently allow this option? Has anyone else encountered this problem?
It was a bug with VSCode that is now fixed.
Your configuration works for me (I copied it in .vscode/tasks.json, closed and reopened the container, and the tasks are executed).