Skip to content

Commit

Permalink
Apply opening brace in nested computation expression identifier. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed May 4, 2020
1 parent 380262a commit 97ddb31
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
19 changes: 19 additions & 0 deletions src/Fantomas.Tests/ComputationExpressionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,22 @@ let f2 =
return r + s
}
"""

[<Test>]
let ``computation expression with app identifier, 806`` () =
formatSourceString false """
[<Tests>]
let tests =
testList "tests"
[
test "test" {
Expect.equal true true "unexpected"
}
]
""" config
|> prepend newline
|> should equal """
[<Tests>]
let tests =
testList "tests" [ test "test" { Expect.equal true true "unexpected" } ]
"""
18 changes: 10 additions & 8 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1128,14 +1128,10 @@ and genExpr astContext synExpr =
fun (ctx:Context) ->
let hasPar = hasParenthesis e2
let addSpaceBefore = addSpaceBeforeParensInFunCall e1 e2 ctx
let isCompExpr =
match e2 with
| CompExpr _ -> true
| _ -> false
let genApp =
atCurrentColumn (
genExpr astContext e1
+> onlyIf isCompExpr (sepSpace +> sepOpenSFixed +> sepSpace)
+> onlyIf (isCompExpr e2) (sepSpace +> sepOpenSFixed +> sepSpace)
+> ifElse
(not astContext.IsInsideDotGet)
(ifElse hasPar
Expand Down Expand Up @@ -1165,9 +1161,15 @@ and genExpr astContext synExpr =
else
sepSpace ctx

atCurrentColumn (genExpr astContext e +>
colPre sepSpace sepSpace es (fun e ->
indent +> appNlnFun e (indentIfNeeded +> genExpr astContext e) +> unindent))
atCurrentColumn
(genExpr astContext e
+> colPre sepSpace sepSpace es (fun e ->
indent
+> appNlnFun e
(indentIfNeeded
+> onlyIf (isCompExpr e) (sepSpace +> sepOpenSFixed +> sepSpace)
+> genExpr astContext e)
+> unindent))

| TypeApp(e, ts) -> genExpr astContext e -- "<" +> col sepComma ts (genType astContext false) -- ">"
| LetOrUses(bs, e) ->
Expand Down
2 changes: 2 additions & 0 deletions src/Fantomas/SourceParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,8 @@ let (|CompExpr|_|) = function
Some(isArray, expr)
| _ -> None

let isCompExpr = function | CompExpr _ -> true | _ -> false

let (|ArrayOrListOfSeqExpr|_|) = function
| SynExpr.ArrayOrListOfSeqExpr(isArray, expr, _) ->
Some(isArray, expr)
Expand Down

0 comments on commit 97ddb31

Please sign in to comment.