From ab1ad7c18b281b024401327bbe6c24a312be4c1d Mon Sep 17 00:00:00 2001 From: Florian Verdonck Date: Sat, 29 May 2021 13:36:07 +0200 Subject: [PATCH] Print trivia after arrow in last clause. Fixes #1759. (#1760) --- src/Fantomas.Tests/KeepIndentInBranchTests.fs | 39 +++++++++++++++++++ src/Fantomas/CodePrinter.fs | 6 ++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/Fantomas.Tests/KeepIndentInBranchTests.fs b/src/Fantomas.Tests/KeepIndentInBranchTests.fs index f3db95650c..57d3a0bbbb 100644 --- a/src/Fantomas.Tests/KeepIndentInBranchTests.fs +++ b/src/Fantomas.Tests/KeepIndentInBranchTests.fs @@ -1689,3 +1689,42 @@ module Foo = 0 """ + +[] +let ``comment after arrow, 1759`` () = + formatSourceString + false + """ +let mapOperationToWebPart (operation: OpenApiOperationDescription) : SynExpr = + let verb = mkIdentExpr (operation.Method.ToUpper()) + let route = + match operation with + | _ -> // no route parameters + let route = mkAppNonAtomicExpr (mkIdentExpr "route") (mkStringExprConst operation.Path) + let responseHttpFunc = + mkLambdaExpr [ ] unitExpr + |> mkParenExpr + infixFish route responseHttpFunc + + infixFish verb route +""" + config + |> prepend newline + |> should + equal + """ +let mapOperationToWebPart (operation: OpenApiOperationDescription) : SynExpr = + let verb = mkIdentExpr (operation.Method.ToUpper()) + + let route = + match operation with + | _ -> // no route parameters + + let route = + mkAppNonAtomicExpr (mkIdentExpr "route") (mkStringExprConst operation.Path) + + let responseHttpFunc = mkLambdaExpr [] unitExpr |> mkParenExpr + infixFish route responseHttpFunc + + infixFish verb route +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 2d677cb459..00cd8e7627 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -5314,7 +5314,11 @@ and genLastClauseKeepIdent (astContext: ASTContext) (Clause (pat, expr, whenExpr +> genPat astContext pat +> sepSpace +> optSingle (genExpr astContext) whenExpr - +> sepArrowFixed + +> (fun ctx -> + let arrowRange = + ctx.MkRange pat.Range.End expr.Range.Start + + tokN arrowRange FsTokenType.RARROW sepArrowFixed ctx) +> sepNln +> (let t, r = synExprToFsAstType expr in sepNlnConsideringTriviaContentBeforeForMainNode t r) +> genExprKeepIndentInBranch astContext expr