Setting up LSP with clangd


Editors such as Emacs, Vim, or VS Code support features like code navigation, code completion, inline compiler error messages, and others, through LSP, the Language Server Protocol. A common language server with LSP support is clangd, which relies on the presence of compile_commands.json, a JSON file with a record of the compile commands for each file in a project.

How do I generate compile_commands.json for XLA source code?

Use the build_tools/lint/ script. The following invocation from XLA repo root generates a compile_commands.json file in place: bash bazel aquery "mnemonic(CppCompile, //xla/...)" --output=jsonproto | \ python3 build_tools/lint/