Recommended Visual Studio Code configuration for PID
Disclaimer
- These instructions are subjective and not absolute requirements. Other solutions exist so feel free to experiment.
- These instructions are subject to change with new versions of Visual Studio Code or the available plugins.
Install Visual Studio Code on your workstation
Please refer to the official documentation and follow the instructions for your platform.
Use the vscode PID environment
Before going further, makes sure your PID workspace is up to date by running:
pid workspace upgrade
To facilitate the installation, configuration and integration of Visual Studio Code with PID you can enable the vscode environment by running:
pid workspace profiles cmd=add env=vscode
This will install the following default extensions:
- C/C++: official Microsoft extension for C/C++. We use it for debugging only, the rest is handled by clangd
- clangd: code completion, formatting, navigation and refactoring
- CMake: syntax highlighting and code completions
- CMake Tools: build CMake projects from the editor
- Doxygen Documentation Generation: generate Doxygen comments for your functions, classes, etc
This will activate the compile_commands environment as well.
Then, when a native PID package is configured, three files will be generated:
.vscode/settings.json: custom settings for the installed extensions. They should be good defaults but you can change them on a per project basis, PID won’t override what is already set.vscode/launch.json: debugger configuration file. This will only be generated for debug builds, so you need to turn offBUILD_RELEASE_ONLYon your packages (or turn onFORCE_DUAL_MODEon the workspace) to make use of it. Once the configuration file has been generated you will have a drop down menu at the top of theRun and Debugtab to select which program (application, example or test) to run. You can edit the launch parameters by clicking the wheel right next to the drop down menu. PID won’t override your modifications to this file, it will only append new configurations when new components are added to the package.compile_commands.json: list of all compiler invocations generated by CMake itself. Used byclangdand other tools.
On the first opening of Visual Studio Code after the extensions have been installed, you will be prompted with the following notification:
The 'clangd' language server was not found on your PATH. Would you like to download and install clangd x.y.z?
Click the Install button and once the installation if finished, click on the new Reload window button.
After this reload, a new notification will show up:
This workspace wants to set clangd.arguments to ["-header-insertion=never"]. This will override your default of [].
Click the Yes use this setting button. This settings prevents clangd to add include statements for missing headers. The issue is that these headers can be ones from the standard library but with system specific paths, e.g /usr/include/c++/12.2.0/vector, which will break your code once compiled on a different system or possibly after an update of yours.
Other recommended extensions
Git support
Git is fully supported by default but somme extensions can improve the experience:
- GitLens: git blame annotations, history inspection, etc
- Commitizen: commit message formatting following the conventional commits convention. To enforce the convention on your packages, enable the
conventional_commitsenvironment in your packages’ root CMakeLists.txt file:check_PID_Environment(TOOL conventional_commits)
Miscellaneous
- Atom Keymap: if you come from the Atom IDE, this package will provide the same keybindings as Atom in Visual Studio Code
- Live Share: allow collaborative editing inside the same workspace (in the VS Code sense). Useful to get help
- Markdown Preview: preview your Markdown files, such as the READMEs, directly in the editor
- Remote Development: use SSH, Docker or WSL (Windows) for your remote development work
- YAML: lint and format YAML files
- XML Tools: format XML files