Skip to content

Commit

Permalink
Print trivia after closing bracket. Fixes #1073. (#1077)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf authored Sep 3, 2020
1 parent 48c416d commit cd98ed3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/Fantomas.Tests/ListTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1657,3 +1657,31 @@ let x =
// another comment
2 ]
"""

[<Test>]
let ``comment after closing list bracket, 1073`` () =
formatSourceString false """
[ Gen.map5 (fun b1 b2 expr1 expr2 pat ->
SynExpr.ForEach(DebugPointAtFor.No, SeqExprOnly b1, b2, pat, expr1, expr2, zero))
Arb.generate<_> Arb.generate<_> genSubDeclExpr genSubDeclExpr genSubSynPat ] //
""" config
|> prepend newline
|> should equal """
[ Gen.map5 (fun b1 b2 expr1 expr2 pat ->
SynExpr.ForEach(DebugPointAtFor.No, SeqExprOnly b1, b2, pat, expr1, expr2, zero)) Arb.generate<_> Arb.generate<_>
genSubDeclExpr genSubDeclExpr genSubSynPat ] //
"""

[<Test>]
let ``comment after closing array bracket`` () =
formatSourceString false """
[| Gen.map5 (fun b1 b2 expr1 expr2 pat ->
SynExpr.ForEach(DebugPointAtFor.No, SeqExprOnly b1, b2, pat, expr1, expr2, zero))
Arb.generate<_> Arb.generate<_> genSubDeclExpr genSubDeclExpr genSubSynPat |] //
""" config
|> prepend newline
|> should equal """
[| Gen.map5 (fun b1 b2 expr1 expr2 pat ->
SynExpr.ForEach(DebugPointAtFor.No, SeqExprOnly b1, b2, pat, expr1, expr2, zero)) Arb.generate<_> Arb.generate<_>
genSubDeclExpr genSubDeclExpr genSubSynPat |] //
"""
2 changes: 1 addition & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ and genExpr astContext synExpr =
let shortExpression =
ifElse isArray
(sepOpenA +> genExpr astContext e +> enterRightBracketBar aNode.Range +> sepCloseA)
(sepOpenL +> genExpr astContext e +> enterRightBracket aNode.Range +> sepCloseL)
(sepOpenL +> genExpr astContext e +> enterRightBracket aNode.Range +> sepCloseL +> leaveNodeTokenByName aNode.Range RBRACK)

let bracketsOnSameColumn =
ifElse isArray sepOpenAFixed sepOpenLFixed
Expand Down

0 comments on commit cd98ed3

Please sign in to comment.