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

lib_deps for multiple environment setup are installed, but include paths not modified #4124

Open bentron2000 opened 2 months ago

bentron2000 commented 2 months ago

When working with multiple environments, libraries installed via lib_deps will only have their include path added to c_cpp_properties.json if they are in the first environment listed in platformio.ini.

Example:

[platformio]
default_envs = controller, sensors 

[env:controller]
platform = espressif32
board = esp32dev
framework = arduino
build_src_filter = 
    +<controllerMain.cpp>
lib_deps = 
    lovyan03/LovyanGFX@^1.1.16
    lvgl/lvgl@9.1.0

[env:sensors]
platform = espressif32
board = esp32dev
framework = arduino
build_src_filter = 
    +<sensorsMain.cpp>
lib_deps =
    adafruit/Adafruit AHTX0@^2.0.5 
    adafruit/Adafruit BusIO@^1.16.1

Once platformio has finished downloading the libraries, they can be found in the .pio/libdeps/<env> folders correctly. At this stage, the projects will build properly. However, the c_cpp_properties.json file does not get updated with the appropriate libdeps paths. In this example, only the following lines are added:

"<full_path_to_my_project>/.pio/libdeps/controller/lvgl",
"<full_path_to_my_project>/.pio/libdeps/controller/lvgl/src",
"<full_path_to_my_project>/.pio/libdeps/controller/LovyanGFX/src",

This results in errors in the IDE stating that the libraries cannot be found. While the projects still build, the issue should not be there and it completely borks any related intellisense.

You can see this in action if you change the order of controller and sensors then rebuild the project.

bentron2000 commented 2 months ago

I have just discovered that using 'rebuild intelliSense index' will repopulate the c_cpp_properties.json file with the correct values. I don't feel this is intuitive behaviour. This probably requires some additional documentation or an alternative approach to multi environment setups.