使用 clangd 设置 LSP

背景

Emacs、Vim 或 VS Code 等编辑器通过语言服务器协议 LSP 支持代码导航、代码补全、内嵌编译器错误消息等功能。支持 LSP 的常用语言服务器是 clangd,它依赖于 compile_commands.json 的存在,这是一个 JSON 文件,包含项目中每个文件的编译命令记录。

如何为 XLA 源代码生成 compile_commands.json

使用 build_tools/lint/generate_compile_commands.py 脚本。以下在 XLA 代码库根目录中进行的调用会生成 compile_commands.json 文件:bash bazel aquery "mnemonic(CppCompile, //xla/...)" --output=jsonproto | \ python3 build_tools/lint/generate_compile_commands.py