Skip to content

PolyCam/cmake-tools-clangd-sync

Repository files navigation

CMake Tools → clangd Sync

Bridges CMake Tools and clangd in VS Code by keeping clangd's compilation database in sync with the active CMake configure preset.

The problem

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.

What this extension does

When you switch configure presets in CMake Tools, this extension automatically:

  1. Updates the CompilationDatabase path in your .clangd config file to point at the new build directory
  2. 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.

How it works

  • Listens to CMake Tools' onSelectedConfigurationChanged and onActiveProjectChanged events via the CMake Tools API
  • Calls getBuildDirectory() to resolve the current build directory
  • Makes a targeted edit to the .clangd file in your workspace root — only the CompilationDatabase line 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

Example

After switching to the desktop-release preset, your .clangd file will contain:

CompileFlags:
  CompilationDatabase: out/cmake-desktop-release

If you already have other directives in .clangd (e.g. Add, Remove, Compiler), they are left untouched.

Requirements

Both are declared as extension dependencies and will be installed automatically if missing.

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors