arduino / arduino-ide

Arduino IDE 2.x
https://www.arduino.cc/en/software
GNU Affero General Public License v3.0
2.32k stars 394 forks source link

Incorrect handling of changed case of sketch file name #482

Open DaveTur opened 3 years ago

DaveTur commented 3 years ago

Describe the problem

Arduino IDE incorrectly displays redundant editor tabs after the user renames a secondary sketch file under the following conditions:

πŸ› The user will be confused by the presence of an editor tab for a file that no longer exists. They will not find any way to correct the situation via the Arduino IDE interface. πŸ› The bug can cause a loss of the user's sketch code.

To reproduce

  1. Select File > New Sketch from the Arduino IDE menus.
  2. Click the β–Ό button on the right side of the editor toolbar.
  3. Select "New Tab" from the menu.
  4. In the "Name for new file" field, type Foo.ino
  5. Click the OK button.
  6. Select File > Save As... from the Arduino IDE menus.
  7. Save the sketch to any convenient location.
  8. Select File > Close from the Arduino IDE menus.
  9. Use your file browser or terminal software to rename the file Foo.ino in the sketch folder to foo.ino.
  10. Open the sketch in the Arduino IDE. πŸ› The editor still contains a "Foo.ino" tab in addition to the expected "foo.ino" tab.
  11. Select File > Preferences from the Arduino IDE menus.
  12. Check the box next to "☐ Auto save".
  13. Click the OK button.
  14. Add some text to the "foo.ino" editor tab:
    // hello world
  15. Select the "Foo.ino" editor tab. πŸ˜• The editor does not contain the text that was added to the "foo.ino" editor tab.
  16. Type a character in the "Foo.ino" editor tab. πŸ› An unexpected "The file 'Foo.ino' has been changed on the file system." dialog opens: image
  17. Click the No button.
  18. Type a character in the "Foo.ino" editor tab.
  19. Click the Yes button in the dialog.
  20. Select the "foo.ino" editor tab. πŸ› The previous // hello world contents of the file have been replaced by the characters that were added to the "Foo.ino" editor tab.
  21. Select File > Preferences from the Arduino IDE menus.
  22. Uncheck the box next to "β˜‘ Auto save"
  23. Click the OK button.
  24. Add some text to the "foo.ino" editor tab:
    // foobar
  25. Select File > Save from the Arduino IDE menus. πŸ› An unexpected "The file 'Foo.ino' has been changed on the file system." dialog opens.
  26. Click the Yes button. πŸ› An unexpected "The file 'foo.ino' has been changed on the file system." dialog opens.
  27. Click the Yes button.
  28. Select the "foo.ino" editor tab. πŸ˜• The editor does not contain the text that was added to the "Foo.ino" editor tab.

Expected behavior

Editor tabs always reflect the actual sketch files.

Arduino IDE version

Original report

2.0.0-beta.10

Last verified with

69b7365

Operating system

Operating system version

Additional context

The bug does not apply to renaming using the editor tab control menu's "Rename" item because its dialog refuses to allow such a renaming (https://github.com/arduino/arduino-ide/issues/2272).

Additional Reports

Workaround

  1. Press the Ctrl+Shift+P keyboard shortcut (Command+Shift+P for macOS users) to open the "Command Palette".
  2. Select the "View: Reset Workbench Layout" command from the menu.

Issue checklist

ubidefeo commented 3 years ago

hi @DaveTur Since this has been here for a while (apologies for taking so long to get back to you), would you be able to test if this issue is still present in the latest Beta version? We fixed some tabs issues recently, would be nice if you could either confirm or deny the presence of this bug so we can move it into investigation or close it. Thanks ubi

per1234 commented 2 years ago

I am still able to reproduce this bug using the latest build (2.0.0-rc6-snapshot-522a5c6)

Lorandil commented 1 year ago

I'm experiencing a similar problem: If I press "CTRL+S" the file is saved and immediately a dialog appears stating that the file has changed on disk. If I press "yes" the file in the editor and on the disk(!) are reverted to the original state. Toggling the auto save option doesn't seem to change the behaviour.

I'm using the current v2.0.3 - I can retry with the latest nightly build if you think the problem has been fixed.

per1234 commented 1 year ago

Hi @Lorandil.

I can retry with the latest nightly build if you think the problem has been fixed.

Thanks for the offer, but that won't be necessary. I verified the bug still exists in the latest nightly. We will close this issue once the bug has been fixed.

For now, I'll share the workaround you can use to get a sketch back into a usable state after it has been affected by this bug:

  1. Press the Ctrl+Shift+P keyboard shortcut (Command+Shift+P for macOS users) to open the "Command Palette".
  2. Select the "View: Reset Workbench Layout" command from the menu.
Lorandil commented 1 year ago

Hi @per1234, thanks for the workaround. In the meantime I tried to rename my "Foo.h" to "foo.h" and changed the mixed includes of "Foo.h"/"foo.h" to be all "foo.h". That happens when you are using Windows ;) Let's see if that fixes the problem for me.

Lorandil commented 1 year ago

To make it short - streamlining the file names didn't help.

I used the workaround @per1234 mentioned and that fixed the issue for now.

HattonLe commented 4 months ago

This problem is marked as type imperfection but it is more serious than that. I have noticed several times that the IDE fails to build a project if you for example (in my case I decided to refactor and rename a class) I had been building with a class X10ex.cpp, X10ex.h and then refactored it to X10.cpp, X10.h using external tools \ file manager. Relaunching Arduino IDE it picks up the refactored files in the edit tabs... this is good... but when I do a build the compiler comes up with errors in the original X10ex.cpp file... this is bad! Relaunching IDE \ recompiling doesn't fix the fault.

These days I use Linux only, Ubuntu 22.04 LTS, and using Arduino IDE, the snap version. Version 2.3.2, Date 2024-02-20T09:54:08.669Z (4 months ago) CLI version 0.35.3.file:///media/main/SSD-480GB/IDEBuildBug.jpg When i was using Windows (this problem existed at least a year ago) I used to find the temp folder where the IDE was building from and delete the out of date files myself, but in Linux I haven't found where these are as yet.... (See my next comment for this)

In the attached screenshot, the file X10ex.cpp doesn't exist in my source folder... that error is referring to the old file name prior to refactoring.

IDEBuildBug

HattonLe commented 4 months ago

I found the Arduino IDE temporary build folder... see attached screenshot for its contents. If I manually delete the offending files via a terminal command "rm X10ex.*" I can then successfully build the sketch using the Arduino IDE. IDEBuildBug