fsprojects / fantomas

FSharp source code formatter
https://fsprojects.github.io/fantomas
Other
758 stars 189 forks source link

Unable to format F# 8 extended interpolated strings with curly braces #3028

Closed stefan-schweiger closed 6 months ago

stefan-schweiger commented 6 months ago

Issue created from fantomas-online

Code

let x = "test"

let x1 = $$"""{{x}}"""
let x2 = $$""" {x: {{x}}} """
let x3 = $$"""x: {{x}}{} """

Result

let x = "test"

let x1 = $$"""{{x}"""
let x2 = $$""" {x: {{x}} """
let x3 = $$"""x: {{x}{} """

Problem description

F# 8 introduced extended interpolated string for which you can specify multiple $ signs in front to indicate how many curly braces you need to surround your interpolated code with. It seems like fantomas does not support this syntax and instead just gives me errors.

Formatting <Path>/MyFile.fs leads to invalid F# code

Extra information

Options

Fantomas main branch at 2023-12-22T09:45:59Z - fc341e88f36ab28c3331e0e6455a0f848bf44f33

Default Fantomas configuration

Did you know that you can ignore files when formatting by using a .fantomasignore file? PS: It's unlikely that someone else will solve your specific issue, as it's something that you have a personal stake in.

stefan-schweiger commented 6 months ago

I'm willing to help to fix this, but I don't really know where to start and I feel like this might be a bit of a complicated change?

auduchinok commented 6 months ago

@stefan-schweiger I think it may depend on a fix in the compiler: https://github.com/dotnet/fsharp/issues/16418.

nojaf commented 6 months ago

Thanks for the report, but this is a duplicate of https://github.com/fsprojects/fantomas/issues/3012. https://github.com/dotnet/fsharp/issues/16418 needs a fix for this indeed.