Ionide-vscode-fsharp: Formatting document continuously adds new lines each time it's called

Created on 9 Oct 2019  路  10Comments  路  Source: ionide/ionide-vscode-fsharp

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:

  1. Run F#: New Project and select console
  2. Open the main fs file with an EntryPoint attribute
  3. Right click in the editor and select Format Document
  4. Repeat Step 3.

Expected behavior
The file doesn't change on subsequent saves. (Only the first time)

Screenshots

Environment (please complete the following information):

  • OS: Windows 10 1903
  • Ionide version: 4.2.0 - 08.10.2019
  • VSCode version: 1.38.1
  • dotnet SDK version: 3.0.100
Fantomas bug

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-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

All 10 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yuhr picture yuhr  路  3Comments

cloudRoutine picture cloudRoutine  路  5Comments

isaacabraham picture isaacabraham  路  3Comments

isaacabraham picture isaacabraham  路  5Comments

sivabudh picture sivabudh  路  3Comments