diff --git a/src/Fantomas.Tests/MultilineBlockBracketsOnSameColumnRecordTests.fs b/src/Fantomas.Tests/MultilineBlockBracketsOnSameColumnRecordTests.fs index 6de5c3be35..ae398f8283 100644 --- a/src/Fantomas.Tests/MultilineBlockBracketsOnSameColumnRecordTests.fs +++ b/src/Fantomas.Tests/MultilineBlockBracketsOnSameColumnRecordTests.fs @@ -441,7 +441,9 @@ let ``SynPat.Record in pattern match with bracketOnSeparateLine`` () = |> prepend newline |> should equal """ match foo with -| { Bar = bar ; Level = 12 ; Vibes = plenty ; +| { Bar = bar + Level = 12 + Vibes = plenty Lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " } -> "7" | _ -> "8" diff --git a/src/Fantomas.Tests/NumberOfItemsRecordTests.fs b/src/Fantomas.Tests/NumberOfItemsRecordTests.fs index cb0eb4945a..9da7ad4ea1 100644 --- a/src/Fantomas.Tests/NumberOfItemsRecordTests.fs +++ b/src/Fantomas.Tests/NumberOfItemsRecordTests.fs @@ -382,7 +382,6 @@ type MyRecord = interface IMyInterface """ -[] [] let ``SynPat.Record in pattern match, 1173`` () = formatSourceString false """match foo with diff --git a/src/Fantomas.Tests/RecordTests.fs b/src/Fantomas.Tests/RecordTests.fs index 0791506dce..e1568b0ffb 100644 --- a/src/Fantomas.Tests/RecordTests.fs +++ b/src/Fantomas.Tests/RecordTests.fs @@ -1048,3 +1048,53 @@ module Test = { long_enough: string also_long_enough: string } // Hi I am a comment """ + +[] +let ``multiline SynPat.Record in match clause, 1173`` () = + formatSourceString false """ +match foo with +| { Bar = bar + Level = 12 + Vibes = plenty + Lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " } -> + "7" +| _ -> "8" +""" config + |> prepend newline + |> should equal """ +match foo with +| { Bar = bar + Level = 12 + Vibes = plenty + Lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " } -> + "7" +| _ -> "8" +""" + +[] +let ``multiline SynPat.Record in let binding destructuring`` () = + formatSourceString false """ +let internal sepSemi (ctx: Context) = + let { Config = { SpaceBeforeSemicolon = before; SpaceAfterSemicolon = after } } = ctx + + match before, after with + | false, false -> str ";" + | true, false -> str " ;" + | false, true -> str "; " + | true, true -> str " ; " + <| ctx +""" config + |> prepend newline + |> should equal """ +let internal sepSemi (ctx: Context) = + let { Config = { SpaceBeforeSemicolon = before + SpaceAfterSemicolon = after } } = + ctx + + match before, after with + | false, false -> str ";" + | true, false -> str " ;" + | false, true -> str "; " + | true, true -> str " ; " + <| ctx +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index f2fed9953c..0723fd5c46 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -4298,9 +4298,20 @@ and genPat astContext pat = +> sepCloseA) | PatRecord (xs) -> - sepOpenS - +> atCurrentColumn (colAutoNlnSkip0 sepSemi xs (genPatRecordFieldName astContext)) - +> sepCloseS + let smallRecordExpr = + sepOpenS + +> col sepSemi xs (genPatRecordFieldName astContext) + +> sepCloseS + + // Note that MultilineBlockBracketsOnSameColumn is not taken into account here. + let multilineRecordExpr = + sepOpenS + +> atCurrentColumn (col sepSemiNln xs (genPatRecordFieldName astContext)) + +> sepCloseS + + fun ctx -> + let size = getRecordSize ctx xs + isSmallExpression size smallRecordExpr multilineRecordExpr ctx | PatConst (c, r) -> genConst c r | PatIsInst (TApp (_, [ _ ], _) as t) | PatIsInst (TArray _ as t) ->