I am working on a big C project that builds with CMake/Ninja. I want to have clangd as my language server which requires a compilation database (compile_commands.json), so I export it with:
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
Problem:
The build is done inside a docker so all file paths in the .json file start with the docker's root workspace and that does not match my actual repo's workspace.
The local source file path is /home/$USER/git/...
but in the .json file it is:
{
"directory": "/workspace/git/...",
"command": "...",
"file": "/workspace/git/..."
},
The possible solutions are:
- Set the docker workspace to match the repo's path
- Somehow manipulate the compilation database so that it has the correct paths either by post-processing it or with a special clangd setting (assuming such setting exists).
I'm more interested in the 2nd option because changing the docker workspace name is a heavier change. Any ideas?