Skip to content

Commit

Permalink
print Trivia before entire LetBang expression. Fixes fsprojects#879
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Jun 1, 2020
1 parent 8824f4a commit c9f3dc5
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
57 changes: 57 additions & 0 deletions src/Fantomas.Tests/ComputationExpressionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1315,4 +1315,61 @@ let a =
let! bar = async { return foo a }
return bar
}
"""

[<Test>]
let ``new line between let and let bang, 879`` () =
formatSourceString false """let rec loop () =
async {
let! msg = inbox.Receive()
match msg with
| Handle (eventSource,command,reply) ->
let! stream = eventSource |> eventStore.GetStream
let newEvents =
stream |> Result.map (asEvents >> behaviour command >> enveloped eventSource)
let! result =
newEvents
|> function
| Ok events -> eventStore.Append events
| Error err -> async { return Error err }
do reply.Reply result
return! loop ()
}
""" ({ config with
SpaceBeforeUppercaseInvocation = true
IndentSpaceNum = 2
SpaceAroundDelimiter = false
MultilineBlockBracketsOnSameColumn = true })
|> prepend newline
|> should equal """
let rec loop () =
async {
let! msg = inbox.Receive ()
match msg with
| Handle (eventSource, command, reply) ->
let! stream = eventSource |> eventStore.GetStream
let newEvents =
stream
|> Result.map
(asEvents
>> behaviour command
>> enveloped eventSource)
let! result =
newEvents
|> function
| Ok events -> eventStore.Append events
| Error err -> async { return Error err}
do reply.Reply result
return! loop ()
}
"""
5 changes: 3 additions & 2 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -968,8 +968,9 @@ and genExpr astContext synExpr =
sprintf "%s%s" (if isUse then "use " else "let ") (if isRecursive then "rec " else "")

genLetBinding astContext prefix binding
| LetOrUseBangStatement(isUse, pat, expr, _) ->
ifElse isUse (!- "use! ") (!- "let! ")
| LetOrUseBangStatement(isUse, pat, expr, r) ->
enterNode r // print Trivia before entire LetBang expression
+> ifElse isUse (!- "use! ") (!- "let! ")
+> genPat astContext pat -- " = "
+> autoIndentAndNlnIfExpressionExceedsPageWidth (genExpr astContext expr)
| AndBangStatement(pat, expr) ->
Expand Down

0 comments on commit c9f3dc5

Please sign in to comment.