diff --git a/src/Fantomas.Tests/CommentTests.fs b/src/Fantomas.Tests/CommentTests.fs index 20e85bfd8f..6adcdf6954 100644 --- a/src/Fantomas.Tests/CommentTests.fs +++ b/src/Fantomas.Tests/CommentTests.fs @@ -1558,3 +1558,44 @@ Host // """ + +[] +let ``comment after bracket in record should not be duplicated in computation expression, 1912`` () = + formatSourceString + false + """ +type TorDirectory = + private + { + NetworkStatus: NetworkStatusDocument + } + + static member Bootstrap (nodeEndPoint: IPEndPoint) = + async { + return + { + TorDirectory.NetworkStatus = + NetworkStatusDocument.Parse consensusStr + ServerDescriptors = Map.empty + // comment + } + } +""" + config + |> prepend newline + |> should + equal + """ +type TorDirectory = + private + { NetworkStatus: NetworkStatusDocument } + + static member Bootstrap(nodeEndPoint: IPEndPoint) = + async { + return + { TorDirectory.NetworkStatus = NetworkStatusDocument.Parse consensusStr + ServerDescriptors = Map.empty + // comment + } + } +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index f60b446980..f4cd439297 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -1397,7 +1397,13 @@ and genExpr astContext synExpr ctx = (genExpr astContext e +> sepCloseS) (genExpr astContext e +> unindent - +> enterNodeTokenByName synExpr.Range RBRACE + +> (fun ctx -> + let closingBraceRange = + ctx.MkRangeWith + (synExpr.Range.EndLine, synExpr.Range.EndColumn - 1) + (synExpr.Range.EndLine, synExpr.Range.EndColumn) + + enterNodeTokenByName closingBraceRange RBRACE ctx) +> sepNlnUnlessLastEventIsNewline +> sepCloseSFixed))