How run to VSCode tasks in JavaScript Debug Terminal? - visual-studio-code

I want VSCode to run this task:
{
"label": "Start",
"type": "shell",
"command": "npm run start",
"dependsOn": ["Set Envs"],
"problemMatcher": [],
"presentation": {
"group": "Main",
"reveal": "always",
"close": false
}
In a JavaScript Debug Terminal. Is there a way to do that?

Related

How can I run one task without finishing another in vscode?

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"
]
}
]
}

vs code task shared terminal

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": []
}
]
}

Run terminals on vscode start

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)

VSCode Run Launch configuration via Tasks.json

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?

Ignore error from the preivous build task in tasks.json

I configured tasks.json to build and run the application.
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "make"
},
{
"label": "close the file",
"type": "shell",
"command": "somecommand"
},
{
"label": "Run build",
"dependsOn": [
"build",
"close the file"
],
"dependsOrder": "sequence",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
The flow is first make command will execute and after that somecommand will be executed. The problem is some times make command returns exit code other than zero, Because of that somecommand is not executing. Is there any way to ignore the previous build status and execute the somecommand always?
To ignore error code in task of type shell, simply add some nop command at the end using || operator. Valid for both bash and batch.
Like:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "make || echo 0"
},
{
"label": "close the file",
"type": "shell",
"command": "somecommand"
},
{
"label": "Run build",
"dependsOn": [
"build",
"close the file"
],
"dependsOrder": "sequence",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
In my case a simple Power Shell:
-ErrorAction Ignore
Does the job, but it depends on what you're doing.
Here's the reference for the shell.