[Bug] CMake Swift: Bad compile-commands.json

I am developing a swift package without SPM, instead using CMake, and would like to make use of Sourcekit-LSP in VSCode. However, I am experiencing the issue mentioned Here where my compile_commands.json is not functional. @compnerd I know you helped develop swift support for CMake, do you or anyone else know if there's a way to get this working properly? Or something other than compile_commands.json that will let Sourcekit work with non-SPM libraries?

1 Like

The compile_commands.json only has the compilation commands. However, the Swift compilation model doesn't work the same way as C/C++, so we only have a link phase, which is not part of compile_commands.json. Emitting something which looks like the compile commands should be possible but I've not had time to work on that. I did have at one point the commands being generated, but never got it to be emitted into the file itself.

Okay. Is it possible then to manually specify files for sourcekit? I know it's clunky but still better than not having any intellisense at all.

I'm not sure if there is a way (@akyrtzi, @blangmuir, or someone on that team might know). However, if you are motivated, getting CMake to emit the information would be useful I think.

I’m no cmake pro, but if you got the commands generated, emitting them to the file seems easy enough. Where’s your work in progress on that that I could continue?

I don't have the patch handy right now. It's not exactly easy since wiring up the generation wasn't very straight forward since the two files are built in different phases/areas. The generation is not done in the CMake language but rather in the C++ generator part of CMake.

Did you have something in mind that would be better than writing a compile_commands.json file by hand? That's the only way at the moment.