Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Closed
Assignees
Labels
conclusion: resolvedIssue was resolved topic: codeRelated to content of the project itself topic: language serverRelated to the Arduino Language Server type: imperfectionPerceived defect in any part of project
@per1234

Description

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月07日T07: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

Metadata

Metadata

Assignees

Labels

conclusion: resolvedIssue was resolved topic: codeRelated to content of the project itself topic: language serverRelated to the Arduino Language Server type: imperfectionPerceived defect in any part of project

Type

No type

Projects

No projects

Milestone

No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      AltStyle によって変換されたページ (->オリジナル) /