Skip to content

Commit

Permalink
Print trivia after arrow in last clause. Fixes #1759. (#1760)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed May 29, 2021
1 parent 4383068 commit ab1ad7c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
39 changes: 39 additions & 0 deletions src/Fantomas.Tests/KeepIndentInBranchTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1689,3 +1689,42 @@ module Foo =
0
"""

[<Test>]
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
"""
6 changes: 5 additions & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ab1ad7c

Please sign in to comment.