Specify the path to compile_commands.json in .vscode/settings.json :
compile_commands.json
.vscode/settings.json
"clangd.arguments": [ "--compile-commands-dir=build" ]
In this example, build is a local folder in the project root directory.
build