clangd로 LSP 설정

배경

Emacs, Vim, VS Code와 같은 편집기는 언어 서버 프로토콜인 LSP를 통해 코드 탐색, 코드 작성, 인라인 컴파일러 오류 메시지 등의 기능을 지원합니다. LSP를 지원하는 일반적인 언어 서버는 clangd입니다. 이 서버는 프로젝트 내 각 파일의 컴파일 명령어 레코드가 있는 JSON 파일인 compile_commands.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