VSC PIO - why it does not update upon code change before build?

As per subject, it goes like that: Build throws error. You edit source. Run build again, and it displays old errors pointing to the old source error line which was already corrected. Why ?

It looks like that old version of source is cached some way.
Do I have to issue some sort of save / update before running build again ? What am I missing here ?

To the best of my knowledge it shouldn’t happen. Do you have a project with which this is always reproducable when certain steps are executed?

1 Like

Just an aftertought, is it possible that it is expected to close every terminal screen, as they may be stacking up in old to newest order ?
I am away from the computer now so can’t veryfiy that.

Terminal screen… do you mean the compile/build output? That’s only informational… as long as you’ve saved the file after editing it, PIO should use the latest code very time.

I also haven’t seen that behaviour, so that’s new / different. When you say errors, is this in the ‘problems’ section (meaning it’s IntelliSense, and possibly not updating properly) or the ‘terminal’ section (meaning it’s compile output, and a problem).

Well, that even happen when I do some changes to platformio.ini.
I have added some -D switches - build still refers to the old platformio.ini.
I am probably missing something painfuly obvious.

^^^ since you’re mentioning changes to platformio.ini - which always forces a full rebuild, it sounds like the former, which whilst is annoying, does not prevent anything from working correctly, as IntelliSense is not related to the compile process, and can say that there are errors when there are none. Yes? No?

I’ve just installed PlatformIO with VSCode and the first project I’ve tried (converted from Arduino) is doing exactly this.
Had an error reported after build. Clicked the link to the code in the error. Edited it. Build reports the same error, with the old text in the error message.
Intellisense does track the changes. I even wrote a line of junk in the file, and the Build process does not even see it.

Update: After closing & opening VSCode, it does appear to be working as expected now. Will update if it happens again.
Update2: Some files work fine - changes are Built. Other files in the same project do not. Closing VSCode & reloading does seem to change things. Is VSCode caching files?

When you say “Build reports the same error”, do you refer to the full log in the TERMINAL view or the error as shown in the PROBLEMS view?

And what do you mean by Build process?

Anyhow, the situation is like so:

  • Visual Studio Code is NOT a fully integrated development environment, and it has no plans to become one. Therefore, it loosely integrates development tools such as source code validation while typing, version control, build systems and their output etc.
  • As a result, IntelliSense and PlatformIO’s build system work more or less independently. Since they work on the same source code and use the same compiler settings, they should be mostly in sync, ie. all IntelliSense errors should also appear in PlatformIO’s output. (The opposite is not true as IntelliSense cannot detect linker errors.)
  • The PROBLEMS view is populated by messages from InelliSense and from parsing the PlatfromIO output in the TERMINAL view. Parsing is easily confused. In particular, it does not clear the old messages if you execute pio run manually in the terminal view or even in a separate terminal program. It only does so if you run via a build command (icon in status bar, action in task view etc.) from within Visual Studio Code.

To get rid of the error message, either:

  • build using a Build command (icon in status bar, action in task view etc.), or
  • restart Visual Studio Code.

I was building using the icon in the status bar, and the error was as reported in the terminal, being output during the build process. I didn’t look at the problems view, just the terminal’s build output.
I was going to see if my edits were actually saved to the files on disk, but this project appears to be building without errors now, and if I make edits to the files, it now behaves as expected.
The issue seemed to appear with 2 separate files, and the corrections to those errors were only seen by the build process after closing & restarting VSCode.

This problem persists.
I edited and built the same project using the status bar icon.
The build output appears in the console, with new errors.
I commented out the errors, and re-ran the build, and the newly generated output has the same errors.
The file saved on disk has been changed, with the erroroneous code commented out.

How is the old code persisting? Surely PlatformIO calls the arduino build process passing references to the files on disk?

Update - some further information:
My project does have an additional folder called ‘libs’ in the same folder as the src, with source code in it.
During the build, in .pio several temporary folders are created with variations on ‘libxxx’ containing the compiled .a files.
It appears that changes in the source ‘lib’ files, as compared to the ‘libxxx’, are not being detected and they are not recompiled.

It does appear running a ‘Clean’ does delete all the temporary folders, and a following Build then compiles everything correctly.

Thanks for the investigation. Can you provide the structure of the project folder (files and directories, without .pio directory)? And can you indicate to which file you’ve added the compile error for testing?

I wonder if this has ever been addressed. I can comment the old code out and it still runs. I tried a “clean”, then a “build” then upload and the code that was commented out ran.
Is there a reason/solution for this?

If you can upload a minimal project that does that, with the procedure you used, then please post it.

Thanks Max:
It is a simple if. This runs correctly. I added some code below the digitalWrite that should have run at 30 second intervals like the LED. Instead the new code ran constantly and when I commented the new code out, it still ran. The OP is describing a similar situation where his new code is being ignored.

 if (currentMillis - previousPumpMillis >= BI)
  {
    previousPumpMillis = currentMillis;
    if (ledState == LOW)
    {
      ledState = HIGH;
      //usbSerial.println("LED High");
      //delay(1000);
    }

    else {
      ledState = LOW;
      //usbSerial.println("LED Low");
      //elay(1000);
    }

    digitalWrite(LED_BUILTIN, ledState);

We would really need the full files to get the full picture, there may be other parts to firmware or codepaths that could cause this behavior. Plus the before and after state of the code of course.

The problem is the code I am testing sends me an SMS. If I completely comment out the code that sends the SMS, Clean, Build, and Upload, I still receive SMS. This should be impossible because the SMS code is all commented out. Is there some cache I should be clearing so that my changes are reflected? I mean it is that simple: comented code is still being run, probably from a previous comple.

It seems like a simple question.

If anyone experiences a similar problem, the behavior was not a problem with the code but an Intel update that apparently never made it to my machine. I manually installed the update and the compiler started working correctly.
I appreciate the help @maxgerhardt offered. Thank you Max.
tjk1