|
|
[[_TOC_]]
|
|
|
# Setting Up Visual Studio Code for ELT DevEnv
|
|
|
This is a setup to configure and work on an ELT project using VSCode (or maybe [VSCodium](https://vscodium.com/)?).
|
|
|
This setup contemplates configuring C/C++ and (maybe one day) Python. The user will be able to connect to a remote ELTDEV workstation and work on his project from a local VSCode instance. WAF should have a proper integration when the configuration is finished.
|
|
|
|
|
|
## Installation
|
|
|
Visual Studio Code is not part of the DevEnv and therefore it must be downloaded and installed in your machine.
|
|
|
Once downloaded from https://code.visualstudio.com/download it can be installed by:
|
|
|
*_Note: This is a work in progress, and I'm no way an expert on VSCode. Please share your findings to improve this documentation_*
|
|
|
|
|
|
```
|
|
|
>tar -xf code-stable-x64-1648620864.tar.gz
|
|
|
>mv VSCode-linux-x64/ VSCode-2022
|
|
|
>chmod -R 775 VSCode-2022/
|
|
|
>cd VSCode-2022/bin
|
|
|
>./code
|
|
|
```
|
|
|
## Summary
|
|
|
Following this document, you'll be able to:
|
|
|
- Create a proper [C/C++ configuration](#configure-cc-extension) for the C/C++ Extension on `.vscode/c_cpp_properties.json` file
|
|
|
- Configure [WAF commands](#configure-waf-tasks) to call them as VSCode tasks
|
|
|
- Setup [Run/Debug configurations](#rundebug-configuration) so they can be used inside VSCode
|
|
|
## Prerequisites
|
|
|
A few steps needs to be done on VSCode and in the ELT DevEnv where you want to work remotely.
|
|
|
|
|
|
## Configuration
|
|
|
Configuration of the include paths can be done by creating a c_cpp_properties.json file in the project directory:
|
|
|
Installing extensions is not covered here, but the easiest way is to install them directly from VSCode Extension Tab (<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>X</kbd>), you can also have a look at [Install Extension to Remote Host](#install-extension-to-remote-host)
|
|
|
|
|
|
```
|
|
|
1. Install [VSCode](https://code.visualstudio.com/) on your own PC. Maybe you want to have a look at [VSCode Getting Started page](https://code.visualstudio.com/docs/getstarted/introvideos) or [VSCode shortcuts](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf)
|
|
|
2. VSCode: Install extension [Remote SSH](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh)
|
|
|
3. VSCode: Install Extension [C/C++](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools) on the Remote DevEnv Host
|
|
|
4. VSCode: Install Extension [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) on on the Remote DevEnv Host
|
|
|
5. DevEnv: Clone your project in your ELT DevEnv remote environment.
|
|
|
6. DevEnv: [Create compile_commands.json file](/CompilationDatabase/CompilationDatabase.md) by using `waf clangdb` on your project folder. Remember it has to be done after `waf configure`.
|
|
|
|
|
|
# Configure C/C++ Extension
|
|
|
[Open your project](#opening-a-project-with-the-remote-ssh-extension). Make sure it is opened where the first `wscript` file is.
|
|
|
|
|
|
More information on [C/C++ Official Documentation](https://code.visualstudio.com/docs/languages/cpp) and [FAQ](https://code.visualstudio.com/docs/cpp/faq-cpp#_why-do-i-see-red-squiggles-under-standard-library-types)
|
|
|
|
|
|
## Create C/C++ local Configuration file
|
|
|
The project C/C++ configuration is stored at `.vscode/c_cpp_properties.json`. There are two ways to generate the file: [Automatically](#automatic-creation) or [Manually](#manual-creation)
|
|
|
|
|
|
### Automatic creation
|
|
|
If `compile_commands.json` is already created. Open any hpp/cpp file, after some seconds VSCode will ask if you want to use the `compile_commands.json` file. Accept by pressing yes. This will create a `.vscode/c_cpp_properties.json` file that has the configuration to the `compile_commands.json` file, if the file is already created, it'll just add `"compileCommands": "${workspaceFolder}/build/compile_commands.json"` in the configuration list.
|
|
|
|
|
|

|
|
|
|
|
|
### Manual creation
|
|
|
If `compile_commands.json` is not generated, or the pop-up does not appear. Call the command palette <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>P</kbd> and search for `C/C++: Edit Configurations (JSON)` to generate the file
|
|
|
|
|
|

|
|
|
|
|
|
## Modify the configuration file
|
|
|
Modify the file so it is configured to DevEnv. It is recommended to change `compilerPath`, `cppStandard`, `intelliSenseMode` and add the line `compileCommands` (if not already filled when [created automatically](#automatic-creation)) to make use of the `compile_commands.json` file created.
|
|
|
|
|
|
```json
|
|
|
{
|
|
|
"configurations": [
|
|
|
{
|
|
|
"name": "Linux",
|
|
|
"includePath": [
|
|
|
"${workspaceFolder}/**",
|
|
|
"${env:INTROOT}/**",
|
|
|
"/opt/rh/gcc-toolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9/../../../../include/c++/9/**",
|
|
|
"/opt/rh/gcc-toolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9/../../../../include/c++/9/x86_64-redhat-linux/**",
|
|
|
"/opt/rh/gcc-toolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9/../../../../include/c++/9/backward/**",
|
|
|
"/opt/rh/gcc-toolset-9/root/usr/lib/gcc/x86_64-redhat-linux/9/include/**",
|
|
|
"/usr/local/include/**",
|
|
|
"/opt/rh/gcc-toolset-9/root/usr/include/**",
|
|
|
"/usr/include/**",
|
|
|
"/opt/protobuf/include/**",
|
|
|
"/elt/mal/include/**",
|
|
|
"/opt/boost/include/**",
|
|
|
"/opt/log4cplus/include/**",
|
|
|
"/opt/cpp-netlib-uri/include/**",
|
|
|
"/opt/opentracing/opentracing-cpp-1.6.0/include/**",
|
|
|
"/opt/zeromq/include/**",
|
|
|
"/opt/open62541/include/open62541/**",
|
|
|
"/opt/anaconda3/include/python3.7m/**",
|
|
|
"/opt/hiredis/include/hiredis/**",
|
|
|
"/opt/azmq/include/**",
|
|
|
"/elt/**"
|
|
|
"${workspaceFolder}/**"
|
|
|
],
|
|
|
"defines": [],
|
|
|
"compilerPath": "/usr/bin/gcc",
|
|
|
"compilerPath": "/opt/rh/gcc-toolset-9/root/usr/bin/gcc",
|
|
|
"cStandard": "c17",
|
|
|
"cppStandard": "c++17",
|
|
|
"intelliSenseMode": "linux-clang-x64"
|
|
|
"intelliSenseMode": "linux-gcc-x64",
|
|
|
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
|
|
|
}
|
|
|
],
|
|
|
"version": 4
|
|
|
}
|
|
|
```
|
|
|
|
|
|
## Build
|
|
|
The building of the project can be done by creating a task.json file in the project directory:
|
|
|
When finished, [intellisense](https://code.visualstudio.com/docs/editor/intellisense) will start parsing the files, it'll take a while since it'll build it's cache (tipically at ~/.cache/vscode-cpptools/ipch`).
|
|
|
|
|
|
```
|
|
|
# Configure WAF Tasks
|
|
|
Telling how to build the project will be needed for Running/Debugging the code later. This is done by configuring WAF Tasks on VSCode. More information of task can be found in the [Official Documentation](https://code.visualstudio.com/docs/editor/tasks)
|
|
|
|
|
|
## Build Task
|
|
|
Open command palette (<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>P</kbd>) and search for `Tasks: Configure Task`, select `Create tasks.json file fom template`, then the options `Others`
|
|
|
1. The file `.vscode/tasks.json` file will be created, replace/add the following lines:
|
|
|
```json
|
|
|
{
|
|
|
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
|
|
// for the documentation about the tasks.json format
|
|
|
"version": "2.0.0",
|
|
|
"tasks": [
|
|
|
{
|
|
|
"label": "waf",
|
|
|
"label": "WAF Configure",
|
|
|
"type": "shell",
|
|
|
"command": "waf build",
|
|
|
"problemMatcher": [
|
|
|
"$gcc"
|
|
|
]
|
|
|
}
|
|
|
"command": "waf",
|
|
|
"args": [
|
|
|
"configure"
|
|
|
],
|
|
|
"group": "build",
|
|
|
"options": {
|
|
|
"cwd": "${workspaceFolder}"
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
"label": "WAF Build",
|
|
|
"type": "shell",
|
|
|
"command": "waf",
|
|
|
"args": [
|
|
|
"build"
|
|
|
],
|
|
|
"group": {
|
|
|
"kind": "build",
|
|
|
},
|
|
|
"problemMatcher": {
|
|
|
"base": "$gcc",
|
|
|
"fileLocation": ["relative", "${workspaceFolder}/build"],
|
|
|
},
|
|
|
"options": {
|
|
|
"cwd": "${workspaceFolder}",
|
|
|
"kind": "build"
|
|
|
},
|
|
|
"detail": "compiler: waf"
|
|
|
},
|
|
|
{
|
|
|
"label": "WAF Clean",
|
|
|
"type": "shell",
|
|
|
"command": "waf",
|
|
|
"args": [
|
|
|
"clean"
|
|
|
],
|
|
|
"group": "build",
|
|
|
"options": {
|
|
|
"cwd": "${workspaceFolder}",
|
|
|
"kind": "build"
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
"label": "WAF Compile Commands (clangdb)",
|
|
|
"type": "shell",
|
|
|
"command": "waf",
|
|
|
"args": [
|
|
|
"clangdb"
|
|
|
],
|
|
|
"group": "build",
|
|
|
"options": {
|
|
|
"cwd": "${workspaceFolder}",
|
|
|
"kind": "build"
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
"label": "WAF Test",
|
|
|
"type": "shell",
|
|
|
"command": "waf",
|
|
|
"args": [
|
|
|
"test"
|
|
|
],
|
|
|
"group": {
|
|
|
"kind": "test",
|
|
|
"isDefault": true
|
|
|
},
|
|
|
"options": {
|
|
|
"cwd": "${workspaceFolder}",
|
|
|
"kind": "test"
|
|
|
},
|
|
|
"problemMatcher": []
|
|
|
},
|
|
|
{
|
|
|
"label": "WAF All Test",
|
|
|
"type": "shell",
|
|
|
"command": "waf",
|
|
|
"args": [
|
|
|
"test",
|
|
|
"--alltests"
|
|
|
],
|
|
|
"group": {
|
|
|
"kind": "test",
|
|
|
"isDefault": true
|
|
|
},
|
|
|
"options": {
|
|
|
"cwd": "${workspaceFolder}",
|
|
|
"kind": "test"
|
|
|
},
|
|
|
"problemMatcher": []
|
|
|
},
|
|
|
]
|
|
|
}
|
|
|
```
|
|
|
|
|
|
and by creating a settings.json file in the project directory (TBC if it is really needed):
|
|
|
## Calling WAF Build or Configure
|
|
|
Now you can start waf build, configure, clangdb and clean by pressing <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>B</kbd> and selecting from the command palette `WAF Build` or `WAF Configure`, `Waf Compile Commands` and `Waf Clean` respectively.
|
|
|
|
|
|
```
|
|
|
{
|
|
|
"C_Cpp.default.compileCommands": "waf build",
|
|
|
"files.associations": {
|
|
|
"functional": "cpp"
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
A task can be selected to be used by default. To configure this:
|
|
|
1) Call the Command Pallete (<kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>P</kbd>) and type `Tasks: Configure Default Build Task`
|
|
|
2) Select `WAF Build`
|
|
|
3) Everytime when using <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>B</kbd>, it'll call `WAF Build` task.
|
|
|
|
|
|
## Debugging
|
|
|
An application can be debugged by creating a launch.json file in the project directory:
|
|
|
## Calling Any Task
|
|
|
To call any task, use `Quick Open` (<kbd>Ctrl</kbd> + <kbd>P</kbd>) and write `task` and press Space, after that, all tasks will be available on a list to be selected.
|
|
|
|
|
|
```
|
|
|

|
|
|
|
|
|
## Calling WAF Test
|
|
|
You can also run tests by calling the command palette <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>P</kbd> and search for `Tasks: Run Test Task`
|
|
|
|
|
|
# Run/Debug configuration
|
|
|
|
|
|
To enable Debugging:
|
|
|
1. Call Command palette <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>P</kbd> and look for `C/C++: Add Debug Configuration`, select `(gdb) launch`
|
|
|
2. This will create the file `.vscode/launch.json`
|
|
|
3. Replace the content with:
|
|
|
```json
|
|
|
{
|
|
|
"version": "0.2.0",
|
|
|
"configurations": [
|
|
|
{
|
|
|
"name": "Debug ciiServer",
|
|
|
"name": "<your_executable> Attach",
|
|
|
"type": "cppdbg",
|
|
|
"request": "attach",
|
|
|
"program": "${workspaceFolder}/build/<Path_to_your_created_exec>",
|
|
|
"preLaunchTask": "WAF Build",
|
|
|
"args": ["--config", "<arg1>", "<arg2>" "-l", "DEBUG"],
|
|
|
"environment": [
|
|
|
{
|
|
|
"name": "LD_LIBRARY_PATH",
|
|
|
"value": "${workspaceFolder}/build/<your_created_libs:${env:LD_LIBRARY_PATH}"
|
|
|
}
|
|
|
],
|
|
|
"processId": "${command:pickProcess}",
|
|
|
"MIMode": "gdb",
|
|
|
"setupCommands": [
|
|
|
{
|
|
|
"description": "Enable pretty-printing for gdb",
|
|
|
"text": "-enable-pretty-printing",
|
|
|
"ignoreFailures": true
|
|
|
},
|
|
|
{
|
|
|
"description": "Set Disassembly Flavor to Intel",
|
|
|
"text": "-gdb-set disassembly-flavor intel",
|
|
|
"ignoreFailures": true
|
|
|
}
|
|
|
]
|
|
|
},
|
|
|
|
|
|
{
|
|
|
"name": "<your_executable> Launch",
|
|
|
"type": "cppdbg",
|
|
|
"request": "launch",
|
|
|
"program": "${workspaceFolder}/build/rad/cpp/_examples/exciiserver/exCiiServer",
|
|
|
"args": [
|
|
|
"-cconfig/exciiserver/config.yaml",
|
|
|
"-lDEBUG"
|
|
|
"program": "${workspaceFolder}/build/<Path_to_your_created_exec>",
|
|
|
"preLaunchTask": "WAF Build",
|
|
|
"args": ["--config", "<arg1>", "<arg2>" "-l", "DEBUG"],
|
|
|
"environment": [
|
|
|
{
|
|
|
"name": "LD_LIBRARY_PATH",
|
|
|
"value": "${workspaceFolder}/build/<your_created_libs:${env:LD_LIBRARY_PATH}"
|
|
|
}
|
|
|
],
|
|
|
"stopAtEntry": false,
|
|
|
"cwd": "${workspaceFolder}",
|
|
|
"cwd": "${fileDirname}",
|
|
|
"environment": [],
|
|
|
"externalConsole": false,
|
|
|
"MIMode": "gdb",
|
|
|
"setupCommands": [
|
|
|
{
|
|
|
"description": "Enable pretty-printing for gdb",
|
|
|
"text": "-enable-pretty-printing",
|
|
|
"ignoreFailures": true
|
|
|
}
|
|
|
],
|
|
|
"miDebuggerPath": "/opt/rh/gcc-toolset-9/root/usr/bin/gdb"
|
|
|
}
|
|
|
{
|
|
|
"description": "Enable pretty-printing for gdb",
|
|
|
"text": "-enable-pretty-printing",
|
|
|
"ignoreFailures": true
|
|
|
},
|
|
|
{
|
|
|
"description": "Set Disassembly Flavor to Intel",
|
|
|
"text": "-gdb-set disassembly-flavor intel",
|
|
|
"ignoreFailures": true
|
|
|
}
|
|
|
]
|
|
|
}
|
|
|
|
|
|
]
|
|
|
}
|
|
|
``` |
|
|
\ No newline at end of file |
|
|
```
|
|
|
4. Modify `"name"`, `"program"`, `"args"`, `"environment"` or any other tag needed for your Debug/Run setup.
|
|
|
4. Now you can start a debugging session by going to menu `Run -> Start Debugging` or by pressing <kbd>F5</kbd> or Run it by pressing `Run -> Run without Debugging` (<kbd>Shift</kbd> + <kbd>F5</kbd>)
|
|
|
|
|
|
# Tools clang-tidy and clang-format
|
|
|
|
|
|
_TODO: Maybe in the next version! meanwhile check [this](https://devblogs.microsoft.com/cppblog/visual-studio-code-c-december-2021-update-clang-tidy/https://devblogs.microsoft.com/cppblog/visual-studio-code-c-december-2021-update-clang-tidy/)_
|
|
|
|
|
|
# Configuration for Python
|
|
|
|
|
|
## wscript file association
|
|
|
If VSCode is not detecting `wscript` files as Python, do the following:
|
|
|
|
|
|
1) Open any wscript file
|
|
|
2) Open the command palette <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>P</kbd>
|
|
|
3) Type `Change Language Mode`
|
|
|
4) Select Option `Configure File Association for 'wscript'`
|
|
|
5) Select/Find `Python`
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
# Appendix
|
|
|
## Opening a project with the Remote SSH extension
|
|
|
A quick tour on how to create a SSH connection, for much detailed information go to the [Official Documentation](https://code.visualstudio.com/docs/remote/ssh)
|
|
|
|
|
|
### Create an SSH Target
|
|
|
1) On the left side menu, click on `Remote Explorer` icon.
|
|
|
2) A pop-up `Enter SSH Connection Command` will appear, type the ssh command to connect. For example `ssh <user>@<host>`
|
|
|
|
|
|

|
|
|
|
|
|
3) The target will be created and will appear on the SSH Target list on the `Remote Explorer` panel.
|
|
|
4) (Optional) You can edit the name of the target by pressing the `Configure` button on the `SSH Target` bar.
|
|
|
|
|
|
### Open the project
|
|
|
Once the connection is done, go to `Explorer panel` and select `Open Project`, select the root folder of the project (the forder containing the `wscript` file with `declare_project`).
|
|
|
|
|
|
## Install extension to remote host
|
|
|
When connected to remote host, install the extensions by going to the extensions tab, and pressing the button `Install in SSH: <your_host>`
|
|
|
|
|
|

|
|
|
|
|
|
## Useful Extensions
|
|
|
* [Atom One Dark Theme](https://marketplace.visualstudio.com/items?itemName=akamud.vscode-theme-onedark): A Very pleasant color scheme
|
|
|
* ~~[Rainbow Brackets](https://marketplace.visualstudio.com/items?itemName=2gua.rainbow-brackets)~~ VSCode supports this already, no need for extension.
|
|
|
* [GitLens](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens): Git inline information
|
|
|
* [Task Explorer](https://marketplace.visualstudio.com/items?itemName=spmeesseman.vscode-taskexplorer): Launch tasks easily
|
|
|
* [Cpp Reference](https://marketplace.visualstudio.com/items?itemName=Guyutongxue.cpp-reference): <kbd>Ctrl</kbd> + <kbd>Shift</kbd> + <kbd>A</kbd> on a STL function will take you to the CppReference documentation.
|
|
|
* [Code Runner](https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner): Run code snippet or code file for multiple languages
|
|
|
* [CodeSnap](https://marketplace.visualstudio.com/items?itemName=adpyke.codesnap): Take screenshots to share your code |