Skip to content

Commit

Permalink
Merge pull request #1076 from nojaf/fix-1072
Browse files Browse the repository at this point in the history
Print trivia for SynExpr.While
  • Loading branch information
nojaf authored Sep 3, 2020
2 parents 2eb1f15 + 250f995 commit 48c416d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Fantomas.Tests/ControlStructureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -526,3 +526,35 @@ let genPropertyWithGetSet astContext (b1, b2) rangeOfMember =
+> unindent
| _ -> sepNone
"""

[<Test>]
let ``preserve new line before while loop, 1072`` () =
formatSourceString false """
let internal coli f' (c: seq<'T>) f (ctx: Context) =
let mutable tryPick = true
let mutable st = ctx
let mutable i = 0
let e = c.GetEnumerator()
while (e.MoveNext()) do
if tryPick then tryPick <- false else st <- f' st
st <- f i (e.Current) st
i <- i + 1
st
""" config
|> prepend newline
|> should equal """
let internal coli f' (c: seq<'T>) f (ctx: Context) =
let mutable tryPick = true
let mutable st = ctx
let mutable i = 0
let e = c.GetEnumerator()
while (e.MoveNext()) do
if tryPick then tryPick <- false else st <- f' st
st <- f i (e.Current) st
i <- i + 1
st
"""
1 change: 1 addition & 0 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2082,6 +2082,7 @@ and genExpr astContext synExpr =
| SynExpr.TryWith _ -> genTriviaFor SynExpr_TryWith synExpr.Range
| SynExpr.New _ -> genTriviaFor SynExpr_New synExpr.Range
| SynExpr.Assert _ -> genTriviaFor SynExpr_Assert synExpr.Range
| SynExpr.While _ -> genTriviaFor SynExpr_While synExpr.Range
| _ -> id)

and genMultilineRecordInstance
Expand Down

0 comments on commit 48c416d

Please sign in to comment.