Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting can depend on cursor position #3007

Closed
DedSec256 opened this issue Dec 4, 2023 · 4 comments · Fixed by #3009
Closed

Formatting can depend on cursor position #3007

DedSec256 opened this issue Dec 4, 2023 · 4 comments · Fixed by #3009

Comments

@DedSec256
Copy link
Contributor

Original issue https://youtrack.jetbrains.com/issue/RIDER-102749

Reproduce via tests in the latest main branch:

[<Test>]
let ``cursor repro 1`` () =
    let result = formatWithCursor
                    """pipeline "init" {
    stage "restore-sln" {
        parallel
        run "dotnet tool restore"
    }
}
"""                 (4, 0)
    result |> assertCursor (4, 0) // Expected: (4,0) But was: (1,15)

[<Test>]
let ``cursor repro 2`` () =
    let result = formatWithCursor
                    """pipeline "init" {
    stage "restore-sln" {
        parallel
        run "dotnet tool restore"
    }
}
"""                 (3, 0)
    result |> assertCursor (3, 0) // Ok

image

@josh-degraw
Copy link
Contributor

I guess I missed something in my testing, I swear I tried to write this exact test and it didn't fail for me haha, thanks for kicking this back over.

@nojaf
Copy link
Contributor

nojaf commented Dec 5, 2023

The strange thing here is that the formatted code is different whether a cursor was inserted or not.

let formatWithCursor source (line, column) =
    let x  = CodeFormatter.FormatDocumentAsync(false, source, FormatConfig.Default) |> Async.RunSynchronously
    
    let y = CodeFormatter.FormatDocumentAsync(false, source, FormatConfig.Default, CodeFormatter.MakePosition(line, column))
    |> Async.RunSynchronously

    // Strangely they differ
    x.Code <> y.Code

@josh-degraw
Copy link
Contributor

Yeah that's why I originally raised this issue, in my case it actually broke my code.

@nojaf
Copy link
Contributor

nojaf commented Dec 6, 2023

Fix available in https://www.nuget.org/packages/fantomas/6.3.0-alpha-004

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants