So, is there any way to detect from within a pre: script that platformio init is being executed, as opposed to a build or upload? Or, is there any way to configure platformio.ini so that it doesn’t invoke a “build” during the init phase?
I’m pretty sure this is by design because extra scripts are able to modify the e.g. include path, and that has to be reflected in the project configuration files for VSCode (c_cpp_properties.json) that platformio -c vscode init -t vscode is supposed to generate correctly.
Marlin Firmware is open in the workspace.
The MOTHERBOARD setting is incompatible with default_env.
It looks like this method (looking for “idedata” inside of COMMAND_LINE_TARGETS doesn’t work in the latest version of the IDE (PIO 5.2.1 / Home 3.3.4). Is there some better (i.e., formally supported) method now for checking whether platformio init is currently executing so that scripts can bail in that case?
Apparently the env.Exit(0) technique to break out of the script is incompatible with IntelliSense in some regard (according to https://github.com/MarlinFirmware/Marlin/pull/23058). So instead of using env.Exit(0) I’m just checking for VSCode initialization as above and then doing nothing in that case.
I don’t think IntelliSense cares about SCONS or PlatformIO, but just parses the source code in its own way, so this shouldn’t have any effect on how IntelliSense interprets things, regardless of whether additional build flags would be added by PlatformIO for the actual build.
The basic issue was… A user reported that env.Exit(0) was interfering with IntelliSense, but I don’t know exactly in what ways, as it seemed to behave well enough for me. But it cleared things up for the complainant once I removed env.Exit(0) and just let the scripts do nothing when vscode init is detected. In the VSCode Developer Tools Console the only clear effect I could see is that env.Exit(0) invokes an onexit handler and dumps a big yellow-box message into the VSCode Developer Tools console. Once I stopped calling env.Exit(0) of course that message no longer appears, as all the script code is simply bypassed.
if set(["_idedata", "idedata"]) & set(COMMAND_LINE_TARGETS):
This code helps you to skip extra scripting when user manually calls pio run -t idedata or when VSCode or other our extensions regenerate C/C++ index via pio project init --vscode (in this case we call internally _idedata).