Skip to content

Commit

Permalink
Put sequential atCurrentColom inside parenthesis. Fixes fsprojects#1805.
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Jul 3, 2021
1 parent 2678660 commit 570d60e
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 1 deletion.
95 changes: 95 additions & 0 deletions src/Fantomas.Tests/LetBindingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1877,3 +1877,98 @@ let a = x in foo x
"""
let a = x in foo x
"""

[<Test>]
let ``let binding as part of sequential inside parenthesis, 1805`` () =
formatSourceString
false
"""
module Foo =
let foo =
lazy (
if not <| bar then
raise <| Exception "Very very very very very very very very very very very very very very long"
let ret = false
if ret then
"foo"
else
"bar"
|> log.Info
ret
)
"""
config
|> prepend newline
|> should
equal
"""
module Foo =
let foo =
lazy
(if not <| bar then
raise
<| Exception "Very very very very very very very very very very very very very very long"
let ret = false
if ret then "foo" else "bar"
|> log.Info
ret)
"""

[<Test>]
let ``sequential inside parenthesis, 1777`` () =
formatSourceString
false
"""
if kind = shiftFlag then (
if errorSuppressionCountDown > 0 then
errorSuppressionCountDown <- errorSuppressionCountDown - 1
#if DEBUG
if Flags.debug then Console.WriteLine("shifting, reduced errorRecoveryLevel to {0}\n", errorSuppressionCountDown)
#endif
let nextState = actionValue action
if not haveLookahead then failwith "shift on end of input!"
let data = tables.dataOfToken lookaheadToken
valueStack.Push(ValueInfo(data, lookaheadStartPos, lookaheadEndPos))
stateStack.Push(nextState)
#if DEBUG
if Flags.debug then Console.WriteLine("shift/consume input {0}, shift to state {1}", report haveLookahead lookaheadToken, nextState)
#endif
haveLookahead <- false
)
"""
config
|> prepend newline
|> should
equal
"""
if kind = shiftFlag then
(if errorSuppressionCountDown > 0 then
errorSuppressionCountDown <- errorSuppressionCountDown - 1
#if DEBUG
if Flags.debug then
Console.WriteLine("shifting, reduced errorRecoveryLevel to {0}\n", errorSuppressionCountDown)
#endif
let nextState = actionValue action
if not haveLookahead then
failwith "shift on end of input!"
let data = tables.dataOfToken lookaheadToken
valueStack.Push(ValueInfo(data, lookaheadStartPos, lookaheadEndPos))
stateStack.Push(nextState)
#if DEBUG
if Flags.debug then
Console.WriteLine(
"shift/consume input {0}, shift to state {1}",
report haveLookahead lookaheadToken,
nextState
)
#endif
haveLookahead <- false
)
"""
3 changes: 2 additions & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1610,7 +1610,8 @@ and genExpr astContext synExpr ctx =
ctx
| Paren (lpr, e, rpr, pr) ->
match e with
| LetOrUses _ ->
| LetOrUses _
| Sequential (_, LetOrUses _, _) ->
sepOpenTFor lpr
+> atCurrentColumn (genExpr astContext e)
+> sepCloseTFor rpr pr
Expand Down

0 comments on commit 570d60e

Please sign in to comment.