playbook/docs/cpp/clangd.md

24 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# clangd 补全配置(`.clangd`
本章节提供 `clangd` 的推荐配置模板与落地要点(参考 `tsl-devkit/lsp-server/.clangd`)。
## 1. 目标
- 让 IDE/编辑器的 C++ 补全、跳转、诊断稳定可复现。
- 优先依赖 `compile_commands.json`(由 CMake 生成),避免手写复杂编译参数。
## 2. 必要前提:生成 `compile_commands.json`
- CMake建议开启 `CMAKE_EXPORT_COMPILE_COMMANDS=ON`(本 Playbook 的 `templates/cpp/CMakeLists.txt` 已开启)。
- 使用 preset 构建后,在对应 build 目录会生成 `compile_commands.json`
- 例如:`build/windows-x86_64-clang-cross/Release/compile_commands.json`
## 3. `.clangd` 模板
- 模板文件:`templates/cpp/.clangd`
- 关键字段:`CompileFlags.CompilationDatabase` 指向 build 目录(包含 `compile_commands.json` 的目录)。
## 4. Modules 注意事项C++23
- 若新增/删除/重命名 `.cppm`,必须同步更新构建系统的模块清单(例如 CMake `FILE_SET CXX_MODULES`),否则 `compile_commands.json` 可能缺项,导致 clangd 补全/跳转不稳定。