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