Bridges CMake Tools and clangd in VS Code by keeping clangd's compilation database in sync with the active CMake configure preset.
CMake Tools and clangd don't talk to each other. When you switch CMake configure presets (e.g. from desktop-debug to desktop-release), clangd keeps using the old compile_commands.json — leading to stale diagnostics, wrong include paths, and missing symbols.
The usual workarounds (manually editing .clangd, symlinking compile_commands.json, restarting clangd) are tedious and error-prone.
When you switch configure presets in CMake Tools, this extension automatically:
- Updates the
CompilationDatabasepath in your.clangdconfig file to point at the new build directory - Restarts clangd so it picks up the new compilation database
That's it. No UI, no commands, no settings. It activates when your workspace contains a CMakePresets.json or CMakeLists.txt and runs silently in the background.
- Listens to CMake Tools'
onSelectedConfigurationChangedandonActiveProjectChangedevents via the CMake Tools API - Calls
getBuildDirectory()to resolve the current build directory - Makes a targeted edit to the
.clangdfile in your workspace root — only theCompilationDatabaseline is changed, all other clangd configuration is preserved - Skips the write and clangd restart entirely if the path hasn't changed
- Uses a relative path when the build directory is inside the workspace
After switching to the desktop-release preset, your .clangd file will contain:
CompileFlags:
CompilationDatabase: out/cmake-desktop-releaseIf you already have other directives in .clangd (e.g. Add, Remove, Compiler), they are left untouched.
Both are declared as extension dependencies and will be installed automatically if missing.