VS Code IntelliSense only applies to active environment while giving errors for the other environment

I have two different environments:

[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
build_src_filter = +<esp.cpp>
lib_deps = 
	nrf24/RF24@^1.4.10
[env:uno]
platform = atmelavr
board = uno
framework = arduino
upload_port = COM8
build_src_filter = +<uno.cpp>
lib_deps = 
	nrf24/RF24@^1.4.10
	lowpowerlab/LowPower_LowPowerLab@^2.2

There is also a Default environment option, but doing anything with it is indistinguishable from [env:nodemcuv2].

The libraries are not identical between environments. Building and uploading to each board individually is a success.

Environment    Status    Duration
-------------  --------  ------------
nodemcuv2      SUCCESS   00:00:00.979
uno            SUCCESS   00:00:00.545

My problem is that every time I switch over from one environment and rebuild IntelliSense, the other src file shows errors. It’s really annoying to have to rebuild IntelliSense every time I want to switch environments. Any solutions to this? I’d prefer to work in the default environment and be able to build both files at once without getting errors for either src file.

You missed to exclude the source code for the other architecture first.

I recommend to create sub folders for each architecture to keep the individual source codes nice, clean and separated.

.
├── .pio
├── .vscode
├── include
├── lib
├── src
│   ├── esp
│   │   └── main.cpp
│   └── uno
│       └── main.cpp
├── test
├── .gitignore
└── platformio.ini

In your platformio.ini for each architecture, first remove everything, then just add the necessary subfolder with all its content to the build_src_filter:

[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
build_src_filter = 
  -<*> 
  +<./esp/*>
lib_deps = 
	nrf24/RF24@^1.4.10

[env:uno]
platform = atmelavr
board = uno
framework = arduino
upload_port = COM8
build_src_filter = 
  -<*> 
  +<./uno/*>
lib_deps = 
	nrf24/RF24@^1.4.10
	lowpowerlab/LowPower_LowPowerLab@^2.2

Of course you will get errors when the uno environment is active and you open some WiFi related code in the esp folder. This is expected behavior.

There is no need to rebuild the intellisense index every time when switching between the environments.

First off, thank you for the reply.

I’ve structured the files as you suggested, and functionally, my issue still persists. Any suggestions on how to make IntelliSense keep up with the active environment without having to rebuild it every time I switch to the other environment?

This is what I mean:
I set my active env. to [env:nodemcuv2] and rebuild IntelliSense; no errors when working on esp/main.cpp file.
img1
When I click on uno/main.cpp, there are errors.
img2
Fair enough, as to be expected. I’m still in the [env:nodemcuv2] env. and that specific file has no bearing on the current board.

But when I switch over to the [env:uno] env.:
img3
I must now manually rebuild my IntelliSense while in the [env:uno] env. if I want to get rid of the errors in the uno/main.cpp file. After rebuilding IntelliSense in the [env:uno] env., I now get errors in my esp/main.cpp file (Img just for context, no intention of working on this file when in the [env:uno]):
img4

Might there be any solution where if I switch from one environment to another:


the IntelliSense automatically associates itself with that file, that board, and those libraries? As of right now, I do have to manually switch environment > rebuild IntelliSense every time I need to go back and forth between editing each board file.

Do you have a settings.json in the projects .vscode folder?
If so, what’s the content?

Do you have multiple projects in your VS Code workspace?

{
    "files.autoSave": "afterDelay",
    "workbench.startupEditor": "none",
    "code-runner.executorMap": {
    
        "javascript": "node",
        "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
        "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "zig": "zig run",
        "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "php": "php",
        "python": "python -u",
        "perl": "perl",
        "perl6": "perl6",
        "ruby": "ruby",
        "go": "go run",
        "lua": "lua",
        "groovy": "groovy",
        "powershell": "powershell -ExecutionPolicy ByPass -File",
        "bat": "cmd /c",
        "shellscript": "bash",
        "fsharp": "fsi",
        "csharp": "scriptcs",
        "vbscript": "cscript //Nologo",
        "typescript": "ts-node",
        "coffeescript": "coffee",
        "scala": "scala",
        "swift": "swift",
        "julia": "julia",
        "crystal": "crystal",
        "ocaml": "ocaml",
        "r": "Rscript",
        "applescript": "osascript",
        "clojure": "lein exec",
        "haxe": "haxe --cwd $dirWithoutTrailingSlash --run $fileNameWithoutExt",
        "rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt",
        "racket": "racket",
        "scheme": "csi -script",
        "ahk": "autohotkey",
        "autoit": "autoit3",
        "dart": "dart",
        "pascal": "cd $dir && fpc $fileName && $dir$fileNameWithoutExt",
        "d": "cd $dir && dmd $fileName && $dir$fileNameWithoutExt",
        "haskell": "runghc",
        "nim": "nim compile --verbosity:0 --hints:off --run",
        "lisp": "sbcl --script",
        "kit": "kitc --run",
        "v": "v run",
        "sass": "sass --style expanded",
        "scss": "scss --style expanded",
        "less": "cd $dir && lessc $fileName $fileNameWithoutExt.css",
        "FortranFreeForm": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "fortran-modern": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "fortran_fixed-form": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "fortran": "cd $dir && gfortran $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        "sml": "cd $dir && sml $fileName"
    },
    "platformio-ide.disablePIOHomeStartup": true,
    "platformio-ide.autoRebuildAutocompleteIndex": false,
    "platformio-ide.autoOpenPlatformIOIniFile": false,
    "platformio-ide.activateProjectOnTextEditorChange": true,
    "editor.wordWrap": "on",
    "editor.tokenColorCustomizations": {
        
    },
    "cmake.configureOnOpen": false,
    "editor.detectIndentation": false,
    "editor.indentSize": "tabSize",
    "editor.tabSize": 2,
    "cmake.showOptionsMovedNotification": false,
    "CodeGPT.apiKey": "KEY",
    "CodeGPT.Autocomplete.enabled": true,
    "C_Cpp.default.compilerPath": "C:\\Install Here\\msys64\\ucrt64\\bin\\g++.exe",
    "security.workspace.trust.untrustedFiles": "open",
    "liveServer.settings.donotShowInfoMsg": true,
    "C_Cpp.files.exclude": {
      
      "**/.vscode": true,
      "**/.vs": true
    }
}

This is the only project open.

There is your answer!

I don’t have any settings.json in my .vscode folder.

Delete or rename that file to “settings.old”.

At least remove this setting and restart VS Code.

That seems to have done the trick; now IntelliSense auto rebuilds every time I switch environment.

A little hiccup after making that change; when making any type of modification in the platform.ini file, IntelliSense now auto rebuilds during typing. As I type any changes to the file, it interrupts the typing to rebuild which makes working with the platform.ini file file nearly impossible. Any suggestions?

This is intended behavior.

While this

is not.

On my system, the index is updated when the platformio.ini is saved to disc, not while typing. So there must be something else on your system.

Are there any other plugins or settings that save files while you’re editing them?

I had the option to auto save any file as I type turned on with a delay of 1 second. Turning that off seems to do the trick. I appreciate all your help. Thank you.