Clangd for “Intellisense” in fVDB
In fVDB we typically develop using Visual Studio Code (VSCode), both local, in containers, and
remove via SSH. To aid development we use clangd for intellisense (code navigation) and to
detect syntax and usage errors before compiling. With clangd active, you will see “red squiggles”
under actual syntax / compilation errors in your code as you edit; you will get code completion
suggestions; and you will get tooltips for definitions when you mouse over code.
The fVDB VSCode workspace includes configuration for clangd but developers new to fVDB should follow these instructions.
Setting up clangd in your environment
The fvdb Conda development environment installs the CUDA toolkit, but clangd runs outside the environment and so may not find the correct CUDA installation. Therefore you should create the file
To fix this, you need to create a user clangd config file to point to the CUDA installation in the
FVDB conda environment: Create ~/.config/clangd/config.yaml with these contents. This assumes you
use the dev_environment.yml to create the fvdb Conda environment.
# https://clangd.llvm.org/config
# Apply a config conditionally to all CUDA files
If:
PathMatch: .*\.cuh?
CompileFlags:
Add:
- "--cuda-path=/home/mharris/miniforge3/envs/fvdb"
The first time you load the fVDB VSCode workspace, it should prompt you to install recommended
extensions. Specifically: “llvm-vs-code-extensions.vscode-clangd”, and
“ms-vscode.cpptools-extension-pack”, as defined in the extensions.json file. Install these
extensions. With Clangd, the MS CPPTools is only used for syntax highlighting. Clangd is used for
intellisense and (CUDA) C++ file formatting.
Troubleshooting Intellisense
Clangd uses the file compile_commands.json to determine the compiler command line used so that it
can build an index of the source code for “intellisense” navigation. This file is generated by
CMake when you configure the build. This happens when you run fVDB’s build.sh. Here are some
tips for troubleshooting intellisense issues.
If you get a red squiggle on the first character of a file, it’s usually a major failure. For example when clangd fails to find the CUDA installation. This is often a configuration problem.
A common problem is when you are editing a file that is not in
compile_commands.json. if this is the case, you may not have CMake-configured your build.A key indicator of this is seeing a message about ‘inferred’ commands like this in the clangd output log
ASTWorker building file XXX with command inferred from YYY
Switching conda environments: if you activate a conda environment, e.g.
fvdb_buildand build (or cmake configure), then switch to another conda environment, yourcompile_commands.jsonwill be out of date with the wrong include paths. You need to rerun cmake configure or rebuild in the active conda environment.red squiggles in google test .cpp : did you build the tests? Are they in compile_commands.cpp? Make sure you add the
gtestsargument to yourbuild.shcommand line:
./build.sh install gtests