History

Add compile_commands.json documentation for C/C++ (#22639)

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 ---------

Justin Simon committed 1 year ago

Commit bbce1c11 parent 2856d0a2 files · +28 −0Browse files

Showing the changes to docs/src/languages/cpp.md (1 of 2 files). Show all

Unified · Split

docs/src/languages/cpp.md+14−0
@@ -98,3 +98,17 @@ Diagnostics: · 97 unmodified lines
9898 ```
9999
100100 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.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t