Rebuild IntelliSense only adds paths for first environment

I am having some trouble with IntelliSense and the use of multiple environments with different platforms.
If I rebuild the index with the “Rebuild IntelliSense Index” command. Only include paths for the first environment are added to .vscode/c_cpp_properties.json.
Therefore IntelliSense does miss a lot of paths for the other other environments.

I tried adding all environments to the default_envs option but it had no effect.

How do I make sure PlatformIO adds all include paths of all environments and their platforms to .vscode/c_cpp_properties.json so IntelliSense works correctly?

[platformio]
default_envs = slave, master

[env:master]
platform = espressif32
board = lolin_d32_pro
framework = arduino

[env:slave]
platform = teensy
framework = arduino
board = teensy40

How is this supposed to work? When you include the correct headers for both environments at once, you get conflicting information for e.g. macro values, mismatches on types (atmelavr-uno int = 2 byte, teensy40 int = 4-byte) or header paths. What should the IDE do when you ask it to follow the header file “SPI.h”? Direct you to <User home>/.platformio/packages/framework-arduinoespressif32/libraries/SPI/src/SPI.h or <user home>/.platformio/packages/framework-arduinoteensy/libraries/SPI/SPI.h? Also the Intellisense would be different depending on which library you look at.

Hmm good point.
What would be the correct/quick way to switch between environments without changing the default_envs all the the time?
Or am I going at this all wrong and should I set my project up in some other way?

Multi-environment projects are still the way to go, but if you want to edit code for one specific environment, I would simply re-generate the Intellisense for a specific environment and work only in that environment.

As you said, you can change the default_envs temporarily to one environment and execute the “Rebuild Intellisense” task, but you can also open a PIO terminal and execute

pio init --ide=vscode -e <environment name here>

so pio init --ide=vscode -e slave e.g.

Only there is no -e option for the init command.
I tried:
pio init --ide=vscode --project-option="default_envs=<environment name>"
According to the documentation but that does not have any effect.

Even building for only a specific target:
pio run -e <environment>
Does not update the c_cpp_properties.json.

There sure must be some easier way to “select” an environment to develop for.

Hm you’re right. Is the “Rebuild intellisense index” task available per-environment? (refer).

Figured out that PlatformIO automatically rebuilds the IntelliSense index c_cpp_properties.json based on the value of default_envs in platformio.ini. If there is no such value it will take the first environment. This happens automatically every few seconds or so. Therefore automatically changing the environment will never have an effect if this is enabled. It can however be disabled in .vscode/settings.json:

{
   "platformio-ide.autoRebuildAutocompleteIndex": false
}

Using environment variables the environment can be overwritten as follows:
export PLATFORMIO_DEFAULT_ENVS=<environment>

After which the IntelliSense index can be updated using the selected environment:
pio init --ide vscode

Combining these in one line:

export PLATFORMIO_DEFAULT_ENVS=<environment> && pio init --ide vscode

Hower it still stucks to execute this command manually, even using a custom task is still an extra step. Looking for a way to do it automatically when building…

3 Likes

Thats exactly what I have been looking for … great!!

Anway … I would vote for integrating this in the IDE in some way as it should be more intuitive!

br J.

Sorry to bump up the old thread, but now you can switch the environment in the bottom blue bar in VSCode. It triggers IntelliSense rebuild.

1 Like