How to handle a symlinked directory with lspconfig/clangd?

Hello! I’m working on a pet project with the Godot game engine and to add custom C++ to the engine, you have to add your code as a module within Godot’s folder structure (godot/modules/my_module). I prefer to have my code within my own repository so I just symlink the directory over into my local clone of the Godot repo.

That all works perfectly fine when compiling but when I try to open one of the files in the symlinked directory, clangd fails to find the compile database. I see this in the logs:

[ERROR][2023-06-12 22:15:06] .../vim/lsp/rpc.lua:734	"rpc"	"/usr/bin/clangd"	"stderr"	"I[22:15:06.259] Failed to find compilation database for /home/paul/src/\nI[22:15:06.259] ASTWorker building file /home/paul/src/ version 0 with command clangd fallback\n[/home/paul/src/]\n/usr/lib/llvm-14/bin/clang /home/paul/src/ -fsyntax-only -resource-dir=/usr/lib/llvm-12/lib/clang/12.0.1\n"

The error makes sense because that path is the actual path to the file; the compile_commands.json database isn’t in a parent folder. It exists in the root directory of the godot repo where I ran the toolchain from to build.

I’ve tested that just copying the folder over instead of using a symlink resolves the issue but that’s not an ideal solution. I also tested using VSCode just to see if it handles this case and it does. Is there a way I can get nvim-lspconfig to use the symlink path instead of the actual path when executing these RPCs against clangd?

For the record I’m opening the file at the symlink path and not the actual path. I.E.:

cd godot
nvim ./modules/my_module/protocol.cpp

I think I figured this out; saw this note in clangd.lua:

If compile_commands.json lives in a build directory, you should symlink it to the root of your source tree.

So I tried just symlinking the compile_commands.json file into the root of my repo and it appears to be working.