Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

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

Justin Simonbbce1c19d1ff
diff --git a/docs/src/languages/c.md b/docs/src/languages/c.md
index 4ae0a0d7c72..cd7191e8eaf 100644
--- a/docs/src/languages/c.md
+++ b/docs/src/languages/c.md
@@ -49,3 +49,17 @@ You can trigger formatting via {#kb editor::Format} or the `editor: format` acti
```
See [Clang-Format Style Options](https://clang.llvm.org/docs/ClangFormatStyleOptions.html) for a complete list of options.
+
+## Compile Commands
+
+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.
+
+### CMake Compile Commands
+
+With CMake, you can generate `compile_commands.json` automatically by adding the following line to your `CMakeLists.txt`:
+
+```cmake
+set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
+```
+
+After building your project, CMake will generate the `compile_commands.json` file in the build directory and clangd will automatically pick it up.
diff --git a/docs/src/languages/cpp.md b/docs/src/languages/cpp.md
index cb2c2c7da3b..0a9eede2583 100644
--- a/docs/src/languages/cpp.md
+++ b/docs/src/languages/cpp.md
@@ -98,3 +98,17 @@ Diagnostics:
```
For more advanced usage of clangd configuration file, take a look into their [official page](https://clangd.llvm.org/config.html).
+
+## Compile Commands
+
+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.
+
+### CMake Compile Commands
+
+With CMake, you can generate `compile_commands.json` automatically by adding the following line to your `CMakeLists.txt`:
+
+```cmake
+set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
+```
+
+After building your project, CMake will generate the `compile_commands.json` file in the build directory and clangd will automatically pick it up.