How can this situation be dealt with?
Well good question. I implemented setting the envvars on purpose into "activated", because otherwise if you have a large workspace with many projects you set envars over and over again for no specific reason. However, if you activate a project you want to work with it, so this makes sense. Also, if you put it into "open" I wonder what happens if you open another project within a WS and then activate another project already existing. This should screw your envvars unless you set them in both: "activated" and "open".
Well, I'm not advocating that they should be set in 'open'. I just tested setting envvars in 'open' to prove they work if set before any other plugin comes into play. 'open' is obviously a bad choice to set them. Maybe changing the plugin loading sequence might work to set the envvars before any other plugin. In what order the plugins are loaded, by name? If yes, what about renaming the plugin to 'aaenvvars' or something (not everywhere, just wherever necessary) to get it to register before any other plugin? I'll try that if I can.
I also spotted a weird behavior which I believe is a bug. When 'Setting -> Environment' is launched, envvars plugin sets the default set no matter what because of the 'LoadSettings()' call in 'EnvVarsConfigDlg::EnvVarsConfigDlg'. I think settings should be loaded at some place where they are only initialized once.
Good spot... Well I want to read the settings here becasue they might have changed... Maybe LoadSettings() should have a flag not to apply them in this case... I don't recall if thats meaningful, I'll have to have a look...
If I'm not mistaken, the only place to change the envvar sets is 'settings -> environment -> environment variables'. If so, where would they have been changed requiring them to be read again? Also apart from loading, they are actually set when 'setting -> environment' is launched. After launching, the user doesn't even need to change anything nor even scroll to the 'environment variables' dialogue for envvars to be set to 'default'. That doesn't seem to the correct behavior. Maybe settings should be loaded and set once in 'OnAttach' or the like and let the plugin change them whenever needed. Just guessing.