clangd is a C++ language server that provides a lot of useful semantics-aware editing features for any editor that supports the Language Server Protocol.
Getting clangd to understand a codebase requires a
compile_commands.json file. We have machinery to generate one,
mach build-backend -b CompileDB.
Unfortunately, clangd doesn't work well with our
compile_commands.json file due to unified compilation.
The entries in our
compile_commands.json file look something like this:
"command": "clang++ <flags> <objdir>/gfx/layers/Unified_gfx_layers1.cpp",
Note that the value of the
"file" key, which is the non-unified source file, does not match the actual input file to the compile command, which is the unified source file.
This confuses clangd, which expects the two to be the same. (Specifically, clangd will interpret the contents of the non-unified file as if it were located in the directory where the unified file is, which breaks resolution of relative include paths.)
We should fix our CompileDB backend to generate a
compile_commands.json that clangd can consume.
Either of the following would work:
- Disable unified compilation for the purposes of generating the CompileDB
- Emit the unified source file under the
"file" key as well, thereby having it match the actual source file used in the command.