[clangd] Invalid AST in header when cpp file uses /TP

CMake-generated compilation databases use “/TP” for cpp files. For some reason, this causes clangd to fail when editing the corresponding header file (“unable to handle compilation”, “invalid AST”).

It looks like the problem is caused by clangd adding “-x c++-header” to the header compilation. In CL mode (windows) this is interpreted as an invalid flag “-x” followed by a request to compile a file called “c++-header”, which is clearly an error.

I’ve tracked the problem down to lib/Tooling/InterpolatingCompilationDatabase.cpp:188-189. Temporarily commenting out those lines solves the problem.

I don’t know enough about the tooling infrastructure to confidently fix the issue. Does anyone know what to do?