Describe the bug
This bug occurred to me because formatOnSave is set to true in my settings.json. When working on the main fs file, continuously saving the file will add more spaces to the file each time it's saved. It seems to have something to do with the attribute syntax which causes the formatter to always add a new line before it. Turns out this behavior can be replicated just my calling Format Document over and over
To Reproduce
Steps to reproduce the behaviour:
F#: New Project and select consoleFormat DocumentExpected behavior
The file doesn't change on subsequent saves. (Only the first time)
Screenshots
Environment (please complete the following information):
Hi, @BornIncompetence:
This is most likely a bug in fantomas so feel free to lodge the issue there as well.
If you want to disable the behaviour in the mean time you can disable format on save for a specific language.
Fantomas has had this bug a few times, so this is probably a regression, make sure its logged at the fantomas repo.
I have a similar problem, but not only are added lines being added at the end of the file, but also added characters, thereby corrupting the file...
I also have format on save enabled.
Before installing Ionide 4.2.0 I was using the the fantomas-fmt extension without problems.(https://marketplace.visualstudio.com/items?itemName=paolodellepiane.fantomas-fmt)
Environment (please complete the following information):
OS: Windows 10 1903
Ionide version: 4.2.0 - 08.10.2019
VSCode version: 1.39.1
dotnet SDK version: 3.0.100
Seconding @nasosev comment.
The character, singular in my case, added at the end of the file (that is, I get a newline that contains a character) is the last character of the file, i.e. the last character of the last line (before the formatter kicks in)
So, for example, if the description was my code, I'd now have a newline containing ')'.
Since I saw this is likely a Fantomas issue, no Ionide (regression, it seems), I'll also comment on that project.
@BornIncompetence I opened an issue over in the Fantomas repo for the issue you're seeing here: https://github.com/fsprojects/fantomas/issues/535
Having the same problem here
Should be fixed in 4.4.x
Should be fixed in
4.4.x
@Krzysztof-Cieslak unfortunately the issue persists for me in 4.4.2. With format on save enabled, source code is corrupted if the file is saved shortly after editing.
@Krzysztof-Cieslak I think the off-by-one PR fixes this as well.
off-by-one fix was released in 4.4.3
Most helpful comment
I have a similar problem, but not only are added lines being added at the end of the file, but also added characters, thereby corrupting the file...
I also have format on save enabled.
Before installing Ionide 4.2.0 I was using the the
fantomas-fmtextension without problems.(https://marketplace.visualstudio.com/items?itemName=paolodellepiane.fantomas-fmt)Environment (please complete the following information):
OS: Windows 10 1903
Ionide version: 4.2.0 - 08.10.2019
VSCode version: 1.39.1
dotnet SDK version: 3.0.100