Ionide-vscode-fsharp: Format document - array formatting bug

Created on 10 Dec 2019  路  8Comments  路  Source: ionide/ionide-vscode-fsharp

Before:
```F#
module Input
let modules = [109024;137172;80445;80044]

**After:**
```F#
module Input

let modules = [ 109024; 137172; 80445; 80044 ]
]

Expected behaviour
F# module Input let modules = [ 109024; 137172; 80445; 80044 ]
To Reproduce
Steps to reproduce the behaviour:

  1. Create file with "before" contents
  2. Press Shift+Alt+F (Format document)

Environment (please complete the following information):

  • OS: Widows 10 Pro 18363.476
  • Ionide version: 4.3.2
  • VSCode version: 1.40.2
  • dotnet SDK version: 3.1.100
  • mono / .Net Framework version: netcoreapp3.1

Additional context
Add any other context about the problem here.

Most helpful comment

You're exactly right. FSAC has been updated with the latest version already, so we need to do an update here of FSAC and this will be addressed. Thanks for reporting!

All 8 comments

Hey @stilettk :wave:,

Thank you for opening an issue. We will get back to you as
soon as we can. Also, check out our OpenCollective and consider
backing us.

https://opencollective.com/ionide

PS.: We offer backer support for all backers. Don't forget to add backer label when you start backing us :smile:

Please open formatting bugs at the fantomas repository, https://github.com/fsprojects/fantomas. We consume them as a library to do all formatting.

This is not reproduced in fantomas: link to online formatter
Maybe ionide doesn't use the latest version?

You're exactly right. FSAC has been updated with the latest version already, so we need to do an update here of FSAC and this will be addressed. Thanks for reporting!

Should be fixed in 4.4.x

@Krzysztof-Cieslak Unfortunately, I can still reproduce it in ionide 4.4.2...

@Krzysztof-Cieslak we should reopen this, the problem seems to be on our side in FSAC.

Given fsx script of:

module Input
    let modules = [109024;137172;80445;80044]

the result of the formatting call is

[Trace - 3:22:08 PM] Sending request 'textDocument/formatting - (62)'.
Params: {
    "textDocument": {
        "uri": "file:///Users/chethusk/oss/CppSharp/build/gmake/lib/Release_x64/gen/scratch.fsx"
    },
    "options": {
        "tabSize": 4,
        "insertSpaces": true
    }
}


[Trace - 3:22:08 PM] Received response 'textDocument/formatting - (62)' in 7ms.
Result: [
    {
        "range": {
            "start": {
                "line": 0,
                "character": 0
            },
            "end": {
                "line": 1,
                "character": 44
            }
        },
        "newText": "module Input\n\nlet modules = [ 109024; 137172; 80445; 80044 ]\n"
    }
]

The key thing is the response has a range of (0,0)-(1,44) (relative to the initial text), and the response text is "module Input\n\nlet modules = [ 109024; 137172; 80445; 80044 ]\n", which is what we expect in this case. I think there's something wrong with the range calculation (because line 2 of the input text (aka line 1 from FSC range perspective) has 45 characters, not 44. I think we're replacing everything from (0,0)-(1,44) with the newText (which ends in newline) and the the last character of ] is being appended.

@baronfel fixed that on FSAC side, fix will be available in next Ionide release

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lilred picture lilred  路  6Comments

draganjovanovic1 picture draganjovanovic1  路  3Comments

isaacabraham picture isaacabraham  路  4Comments

gsomix picture gsomix  路  6Comments

landy picture landy  路  5Comments