VSCode using relative paths in build task on remote set up - linux

I'm trying to add a build task to build the current file, just a simple "make path/to/file.o". I'm using vscode on windows 10 over a remote SSH connection to linux.
However, if I use ${relativeFileDirname} it converts the path separators to windows format. Eg...
${fileDirname}=/home/me/git/project/data/source
${relativeFileDirname}=data\source
I've read about explorer.copyRelativePathSeparator. Can that be applied to the build task in tasks.json? Or is there another way?
This is the build task...
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/make",
"args": [
"${relativeFileDirname}/${fileBasenameNoExtension}.o"
],
"options": {
"cwd": "/home/me/git/project"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/gcc",
"presentation": {
"clear": true
}
}
Thanks.

There is an extension for Visual Studio Code for this purpose that, after many failed attempts to use string substitution with bash built-ins and sed, was the only working solution for me:
"customOptions": "--workdir /home/user/${command:extension.commandvariable.file.relativeFileDirnamePosix}",

Related

Can't debug on vscode get this message: Unable to start debugging. LLDB exited unexpectedly with exit code 134 (0x86)

I'm using an old 2015 macbook air ver 10.13.6
vs code Version: 1.74.0 (Universal)
extensions : C/C++ , Code Runner
I'm learning c++ and here's the basic code I'm trying to test to see if my vscode is good to go
I'm doing this in a C++Projects folder and the file name helloworld.cpp
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!";
return 0;
}
when I run my file it says Build finished successfully.
but afterwards it says unable to start debugging
here are the other files I have that pop up
launch.json :
"configurations": [
{
"name": "C/C++: clang++ build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "C/C++: clang++ build active file"
}
]
tasks.json :
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-fcolor-diagnostics",
"-fansi-escape-codes",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
Please help I've been searching for answers on this and can't seem to find any. Much appreciated!
checked to see if clang was installed. yes
changed the task and launch files
Install the VS Code extension, 'code lldb', with following config:
{
"name": "clang++ - Build and debug active file",
"type": "lldb",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"cwd": "${workspaceFolder}",
"preLaunchTask": "C/C++: clang++ build active file" //<-- your build task name
}

Set a dev container to open a terminal

Is it possible in the dev container specification to specify one or more terminals to be opened as part of the dev container?
My use case is that I'd like to open two terminals for the user:
Build and host the app.
Build and run the app API.
The idea is simply to save the user's time of having to open up the terminals themselves and run the relevant commands.
Same terminal
If you don't need the logs in separate terminals, you can use the postStartCommand lifecycle script.
Add your commands to the devcontainer.json file, with the commands separated by &&; use nohup as in this example to leave the processes running:
"postStartCommand": "echo hello && echo world"
Separate terminals
If you want separate terminals, you can create a custom task; the page also contains info on how to further customize your tasks.
// .vscode/tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build Host",
"type": "shell",
"command": "echo hello",
"group": "build",
"presentation": {
"group": "buildGroup",
"reveal": "always",
"panel": "new",
"echo": false,
}
},
{
"label": "Build API",
"type": "shell",
"command": "echo world",
"group": "build",
"presentation": {
"group": "buildGroup",
"reveal": "always",
"panel": "new",
"echo": false,
}
},
{
"label": "Build All",
"dependsOn": [
"Build Host",
"Build API"
],
"group": "build",
"runOptions": {
"runOn": "folderOpen" // This starts both tasks when the container is started
},
}
]
}
With Run and Debug
Finally, depending on what project your are working on, you can use the launch.json file to set a custom run command. Here you can find the documentation.

Start VScode with named terminals and command ready to start

Everytime I open my vsCode project with multiple projects inside, I need to open multiple terminals and use the command "yarn <project_name>:start". I also rename them with the project name because they all have the name name by default (powershell in my case, then node when the command is launched).
I have 2 questions:
Is there a way to open a predefined list of terminals with a predefined name for each project.
Is there a way to input the command in each terminal with or without lauching the command.
Thank you for your help!
Using vscode tasks, I was able to add 2 tasks and call them together in another tasks that activates automatically on everytime I open the workspace.
{
"label": "Start Dev",
"runOptions": {
"runOn": "folderOpen"
},
"dependsOn": ["Common", "Hub"]
},
{
"label": "Common",
"type": "shell",
"command": "yarn dev:common",
"windows": {
"command": "yarn dev:common"
},
"group": "none",
"presentation": {
"reveal": "always",
"panel": "new"
}
},
{
"label": "Hub",
"type": "shell",
"command": "yarn dev:hub",
"windows": {
"command": "yarn dev:hub"
},
"group": "none",
"presentation": {
"reveal": "always",
"panel": "new"
}
}

How can I call arm-none-eabi-gdb with -x parameter

I want to call arm-none-eabi-gdb with -x parameter when launch debugger after installing cortex-debug. How can I do in launch.json or setting.json, thanks for your help.
You may try adding the following task to our tasks.json the following:
{
"label": "flash",
"type": "shell",
"command": "arm-none-eabi-gdb",
"args": [
"-x=\"${workspaceFolder}/.vscode/flash.gdb\"",
],
"group": "build",
"problemMatcher": [],
"dependsOn":["build"]
},
(of course this assume you have another task called "build" and that your "flash" task depends on it. this is just an example of how to add the -x argument)

Typescript build task in VSCode on Windows 10 with Windows Subsystem for Linux

My VSCode settings (workspace settings in my case) are setup to use bash as the default terminal:
{
"terminal.integrated.shell.windows": "C:\\WINDOWS\\Sysnative\\bash.exe"
}
I need this to be able to debug my app.
My tasks.json looks like that:
{
"version": "2.0.0",
"tasks": [
{
"type": "typescript",
"tsconfig": "./tsconfig.json",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
So when I try to build my project / run the build task (i.e. Ctrl + B), I get the following error:
> Executing task: tsc -p "c:\PATH_TO_MY_PROJECT\tsconfig.json" <
error TS5058: The specified path does not exist: 'c:\PATH_TO_MY_PROJECT\tsconfig.json'.
The terminal process terminated with exit code: 1
If I disable bash in my settings an use the default Windows terminal, the build works fine.
I remember it working few VSCode updates ago, but it stopped working in the latest VSCode versions. Not sure how that's related.
I tried to fix this for a while, but finally gave up on the built-in Typescript task and instead just used a custom task:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Typescript watch",
"type": "shell",
"command": "tsc --watch",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "new"
},
"problemMatcher": [
"$tsc"
]
}
]
}

Resources