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:
- Select File > Preferences from the Arduino IDE menus.
- Uncheck the box next to [] Auto save.
- Click the OK button.
- 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.
- 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.
- 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:If not, start again from step (4) (the issue is somewhat intermittent).void setup() { // put your setup code here, to run once: } v }
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