Fix clangd intellisense problem caused by mismatch between compile_commands.json and real compile commands

impl1.patch (16.8 KB)

impl2.patch (15.3 KB)

UBT enables PCH by default during compilation. However, PCH was turned off when generating compile_commands.json. This mismatch caused clangd to prompt errors, but the compilation still succeeded (of course, the root cause lies in the project not adhering to the IWYU specification when including header files). By introducing an additional -PCHModule parameter for the UBT GenerateClangDatabase mode, specifying that certain modules in the generated compile_commands.json require PCH, we can strive to make compile_commands.json align more closely with the actual compilation behavior.

Attached impl1.patch and impl2.patch are two possible implementations of the aforementioned functionality in engine version 5.4.3. The implementation of impl1.patch is simpler, but it requires the introduction of an additional GCDPCH intermediate directory, occupying more disk space. On the other hand, the implementation of impl2.patch is more intrusive, but it does not require an additional intermediate directory, thus not occupying any additional space.

Help this will help someone who have similar troubles as me.