This document shares some tips and recommendations for using VSCode for ROS development.
- Visual Studio Code Extension for ROS (Details)
- Automatically configures various paths
- Enables clang-format
- CMake Tools
- C/C++ for Visual Studio Code
- For Intellisense/Autocompletion
- ToDo
-
GitHub Pull Requests and Issues
- Checkout/Review/Create PRs from within VSCode
-
- Removes/highlights trailing spaces
In order to have C++ Autocompletion via Intellisense C/C++ for Visual Studio Code is needed.
During the first startup in a new workspace a file .vscode/c_cpp_properties.json
is created at the root of the workspace. This files contains the paths intellisense indexes. To make sure everythink is properly configured the workspace should be sourced before the first start of vscode. A proper .vscode/c_cpp_properties.json
looks something like:
{
"configurations": [
{
"browse": {
"databaseFilename": "",
"limitSymbolsToIncludedHeaders": true
},
"includePath": [
"/opt/ros/foxy/include/**",
"/home/alex/ros2_ws/src/my_package/include/**",
"/usr/include/**"
],
"name": "ROS"
}
],
"version": 4
}
After the first start of vscode the intellisense is building its index. Depending on the hardware resources and the number of files the may take a few seconds. The process is visualized by a small database icon at the lower right. TODO include image.
If all these settings are applied correctly autocomplete for C++ should now work as expected and show suggestions during typing. Use Strg+Space to show the documentation for each suggestion.
- Directly enables clang-format according to ROS style (see https://github.com/ms-iot/vscode-ros/blob/1a31e7eab9b159fd785c21dd0c1edb2d859814b9/src/cpp-formatter.ts#L10-L56)
- Needs clang-format installed. (sudo apt-get install clang-format)
- Usage: (Strg+Shift+P) "Format Document" or "Format Document with ... ROS"
- Right click: Copy Remote Url