Skip to content

Auto Format inappropriately deletes sketch content when "Auto save" is off #543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
per1234 opened this issue Oct 11, 2021 · 2 comments · Fixed by #1019
Closed

Auto Format inappropriately deletes sketch content when "Auto save" is off #543

per1234 opened this issue Oct 11, 2021 · 2 comments · Fixed by #1019
Assignees
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself topic: language server Related to the Arduino Language Server type: imperfection Perceived defect in any part of project

Comments

@per1234
Copy link
Contributor

per1234 commented Oct 11, 2021

Describe the bug

🐛 Tools > Auto Format sometimes deletes arbitrary content of the sketch when the "Auto save" preference is turned off.

To Reproduce

Steps to reproduce the behavior:

  1. Select File > Preferences from the Arduino IDE menus.
  2. Uncheck the box next to [] Auto save.
  3. Click the OK button.
  4. Select File > New from the Arduino IDE menus.
    • This step is not essential. It's just an easy way to get some standardized code to test with.
  5. Add three blank lines in the setup function:
    void setup() {
      // put your setup code here, to run once:
    
    
    
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    
    }
    • The issue is not restricted to this exact code configuration. I have reproduced it with other code, including code that doesn't require legitimate line removal of the formatter tool. But this code is quick and easy to produce and results in dramatically bad changes.
  6. Do an Auto Format (via either Ctrl+T or Tools > Auto Format).
    🐛 Some of the sketch may have been deleted. leaving it looking like this:
    void setup() {
      // put your setup code here, to run once:
    
    
    
    }
    v
    
    }
    If not, start again from step (4) (the issue is somewhat intermittent).

Expected behavior

Auto format only makes the changes dictated by the ClangFormat configuration.

Desktop

  • OS: Windows 10, Ubuntu 20.04
  • Version: 2.0.0-beta.12
    Date: 2021-10-07T07:55:54.325Z
    CLI Version: 0.19.1 alpha [718bbbf2]

Additional context

If you make any significant number of attempts to reproduce the issue, you will likely also encounter the intermittent problem of the formatter ceasing to work altogether (perhaps #396). Once you open a new window the formatter should start working again.

I have never been able to reproduce the issue with the "Auto save" preference enabled.

This may be a duplicate of #45 but I have not managed to reproduce that specific deletion and it doesn't mention a dependency on the "Auto save" configuration.

Originally reported by @UKHeliBob at https://forum.arduino.cc/t/auto-format-settings/698381/14

@per1234 per1234 added topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project topic: language server Related to the Arduino Language Server labels Oct 11, 2021
@per1234
Copy link
Contributor Author

per1234 commented Nov 30, 2021

After the Language Server update provided by #610, I am still able to consistently reproduce this type of issue, but not via the same procedure described above, and not with the same results. The new procedure:

  1. Select File > New from the Arduino IDE menus.
    • This step is not essential. It's just an easy way to get some standardized code to test with.
  2. Add four blank lines in the setup function:
    void setup() {
      // put your setup code here, to run once:
    
    
    
    
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    
    }
  3. While it is still rebuilding the sketch, immediately do an Auto Format (via either Ctrl+T or Tools > Auto Format). Some of the sketch may have been deleted. leaving it looking like this:
    void setup() {
      // put your setup code here, to run once:
    
    
    
    
    
    
    void loop() {
      // put your main code here, to run repeatedly:
    }
    If not, start again from step (4) (the issue is somewhat intermittent).

@per1234
Copy link
Contributor Author

per1234 commented Jun 8, 2022

Closing as fixed by #1019

@per1234 per1234 closed this as completed Jun 8, 2022
@per1234 per1234 added the conclusion: resolved Issue was resolved label Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself topic: language server Related to the Arduino Language Server type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants