Skip to content

Commit

Permalink
Add space after parenthesis function call with lambda argument. Fixes f…
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Jan 22, 2022
1 parent 10eef4b commit 30054b4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
34 changes: 34 additions & 0 deletions src/Fantomas.Tests/LambdaTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1103,3 +1103,37 @@ fun a -> // foo
fun a -> // foo
a
"""

[<Test>]
let ``parenthesis function call with lambda argument, 2015`` () =
formatSourceString
false
"""
(if true then foo else goo) (fun _ -> 42)
"""
config
|> prepend newline
|> should
equal
"""
(if true then foo else goo) (fun _ -> 42)
"""

[<Test>]
let ``parenthesis function call with long lambda argument`` () =
formatSourceString
false
"""
(if true then foo else goo) (fun _ ->
// comment
42)
"""
config
|> prepend newline
|> should
equal
"""
(if true then foo else goo) (fun _ ->
// comment
42)
"""
12 changes: 8 additions & 4 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1974,13 +1974,17 @@ and genExpr astContext synExpr ctx =

// functionName arg1 arg2 (fun x y z -> ...)
| AppWithLambda (e, es, lpr, lambda, rpr, pr) ->
let sepSpaceAfterFunctionName ctx =
let sepSpaceAfterFunctionName =
match List.tryHead es with
| Some (SimpleExpr _) -> sepSpace ctx
| None ->
match e with
| Paren _ -> sepSpace
| _ -> sepNone
| Some (SimpleExpr _) -> sepSpace
| _ ->
match e with
| UppercaseSynExpr -> onlyIf ctx.Config.SpaceBeforeUppercaseInvocation sepSpace ctx
| LowercaseSynExpr -> onlyIf ctx.Config.SpaceBeforeLowercaseInvocation sepSpace ctx
| UppercaseSynExpr -> (fun ctx -> onlyIf ctx.Config.SpaceBeforeUppercaseInvocation sepSpace ctx)
| LowercaseSynExpr -> (fun ctx -> onlyIf ctx.Config.SpaceBeforeLowercaseInvocation sepSpace ctx)

let short =
genExpr astContext e
Expand Down

0 comments on commit 30054b4

Please sign in to comment.