platformio / platformio-vscode-ide

PlatformIO IDE for VSCode: The next generation integrated development environment for IoT
https://marketplace.visualstudio.com/items?itemName=platformio.platformio-ide
Apache License 2.0
1.23k stars 196 forks source link

Generate a compile_commands.json file #2674

Open Trass3r opened 3 years ago

Trass3r commented 3 years ago

This would allow people to use choose clangd as the language server, get clang-tidy warnings in real-time and use other tools based on that json file. It could potentially simplify the clang-tidy integration too which currently calls the tool manually.

Generating one manually is possible via pio run -t compile_commands.json with:

compiledb.py:

Import("env")
env.Tool('compilation_db')
env.CompilationDatabase('compile_commands.json')
extra_scripts =
  pre:compiledb.py

But it would be great to have built-in support so it gets automatically (re-)generated only when the project setup changes (so tools like clangd don't have to restart all the time).

Trass3r commented 3 years ago

It could potentially simplify the clang-tidy integration too which currently calls the tool manually.

Thinking about it, how did that solve the problem of include paths hard-coded into the gcc cross compiler? Those are missing in the json file of course.

jlmxyz commented 2 years ago

sorry for my dumb questions, but I'm new to vscode and would REALLY try clangd use because cpptools aren't great... it often don't find the right symbols or definition... but I don't get what to do with compiledb.py, should I create this file into my source tree? and the extra_scripts, where should it go? tried to launch on console pio run* command given in the exemple, but it says that pio is not found thanks and regards

arbrauns commented 8 months ago

pio run -t compile_commands.json

This doesn't seem to work anymore, it gives me *** Do not know how to make File target `compile_commands.json' (...). Stop.. No other warnings, so I'm guessing the compiledb.py script is loaded correctly.

arbrauns commented 8 months ago

Looks like this is built into platformio somewhere somehow now, the script is no longer required and the command is pio run -t compiledb.