Pio build and compile_commands.json

Hi, I’m using emacs as my editor and have the rather nice ccls integration using lsp to provide completion and navigation as well as enhanced flycheck type functionality. I am using the emacs platformio extension which is nice.

However the ccls package appears to use compile_commands.json to parse and index the source hierarchies.

How do I create a compile_commands.json form pio build?

I am guessing I am missing something obvious in the flags.

Thank you.

1 Like

OK, maybe even somehow I can forcibly regenerate the .clang_complete that is created when I run platformio init --ide emacs --board uno?

How about to make a new “make” target which will run platformio init --ide emacs --board uno?

The .clang_complete file, produced by pio init --ide emacs, is of no help by using language servers like clangd or ccls. It would be nice if platformio could produce a compile_commands.json file, because otherwise emacs is useless if you want to use lsp or eglot.

I don’t know about the internals of platformio, but a compile_commands.json file can be produced by cmake, see https://clang.llvm.org/docs/JSONCompilationDatabase.html

We resolved that in

You can re-test with pio upgrade --dev. The final PIO Core 4.1 is planned for release this month.

Actually you resolved it for ccls which is a different language server than the clangd, which is a product of the llvm developers. For clangd to work one needs a compile_commands.json file not a .clang_complete and/or .ccls file.

I think he knows that. The name is the giveaway. Cmake generates a compile commands file.