Skip to content

Commit

Permalink
Use autoIndentNlnByFuture for let bang. Fixes fsprojects#615
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Mar 13, 2020
1 parent bc86642 commit c5a45b6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
47 changes: 47 additions & 0 deletions src/Fantomas.Tests/ComputationExpressionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,50 @@ observable {
and! b = bar
return a + b }
"""

[<Test>]
let ``let bang should be formatted as regular let, 615`` () =
formatSourceString false """
let f =
async {
// Without binding newline after assignment sign preserved, which is expected behavior
let r =
match 0 with
| _ -> ()
return r
}
let f2 =
async {
// When binding, newline force-removed, which makes the whole expression
// on the right side to be indented.
let! r = match 0 with
| _ -> () |> async.Return
return r
}
""" config
|> prepend newline
|> should equal """
let f =
async {
// Without binding newline after assignment sign preserved, which is expected behavior
let r =
match 0 with
| _ -> ()
return r
}
let f2 =
async {
// When binding, newline force-removed, which makes the whole expression
// on the right side to be indented.
let! r =
match 0 with
| _ -> () |> async.Return
return r
}
"""
11 changes: 5 additions & 6 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1439,17 +1439,16 @@ and genExpr astContext synExpr =
addParenIfAutoNln e1 (genExpr astContext) -- sprintf " <- " +> genExpr astContext e2

| LetOrUseBang(isUse, p, e1, ands, e2) ->

let genAndList astContext (ands: list<SequencePointInfoForBinding * bool * bool * SynPat * SynExpr * range>) =
colPost sepNln sepNln
ands
(fun (_,_,_,pat,expr,_) -> !- "and! " +> genPat astContext pat -- " = " +> genExpr astContext expr)

atCurrentColumn (ifElse isUse (!- "use! ") (!- "let! ")
+> genPat astContext p -- " = " +> genExpr astContext e1 +> sepNln
+> genAndList astContext ands
+> genExpr astContext e2
)
ifElse isUse (!- "use! ") (!- "let! ") +> genPat astContext p -- " = "
+> autoIndentNlnByFuture (genExpr astContext e1)
+> sepNln
+> genAndList astContext ands
+> genExpr astContext e2

| ParsingError r ->
raise <| FormatException (sprintf "Parsing error(s) between line %i column %i and line %i column %i"
Expand Down

0 comments on commit c5a45b6

Please sign in to comment.