Added documentation explaining that clangd requires `compile_commands.json` for proper functionality in both C and C++ projects. Includes instructions for generating the file using CMake. This is related to https://github.com/zed-industries/zed/discussions/6480 Release Notes: - N/A ---------
Showing the changes to docs/src/languages/cpp.md (1 of 2 files). Show all
Unified · Split
| @@ -98,3 +98,17 @@ Diagnostics: · 97 unmodified lines | |||
| 98 | ``` | 98 | ``` |
| 99 | 99 | ||
| 100 | For more advanced usage of clangd configuration file, take a look into their [official page](https://clangd.llvm.org/config.html). | 100 | For more advanced usage of clangd configuration file, take a look into their [official page](https://clangd.llvm.org/config.html). |
| 101 | |||
| 102 | ## Compile Commands | ||
| 103 | |||
| 104 | For some projects Clangd requires a `compile_commands.json` file to properly analyze your project. This file contains the compilation database that tells clangd how your project should be built. | ||
| 105 | |||
| 106 | ### CMake Compile Commands | ||
| 107 | |||
| 108 | With CMake, you can generate `compile_commands.json` automatically by adding the following line to your `CMakeLists.txt`: | ||
| 109 | |||
| 110 | ```cmake | ||
| 111 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
| 112 | ``` | ||
| 113 | |||
| 114 | After building your project, CMake will generate the `compile_commands.json` file in the build directory and clangd will automatically pick it up. | ||