Skip to content

Commit

Permalink
Always add a space for multiple curried args invocation (#2088)
Browse files Browse the repository at this point in the history
Fixes #2087

Co-authored-by: ijanus <emekamicro@gmail.com>
  • Loading branch information
2 people authored and nojaf committed Mar 4, 2022
1 parent 31f71b9 commit 6274245
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
18 changes: 18 additions & 0 deletions src/Fantomas.Tests/AppTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -905,3 +905,21 @@ promise {
|> Promise.start
"""

[<Test>]
let ``function invocation with multiple curried parameters, 2087`` () =
formatSourceString
false
"""
module Foo =
let Bar (baz1: int) (baz2: string) (baz3: string) (baz4: string) (baz5: string) =
FooBarBaz(someFunc x) (someOtherFunc y)
"""
config
|> prepend newline
|> should
equal
"""
module Foo =
let Bar (baz1: int) (baz2: string) (baz3: string) (baz4: string) (baz5: string) =
FooBarBaz (someFunc x) (someOtherFunc y)
"""
2 changes: 1 addition & 1 deletion src/Fantomas.Tests/PatternMatchingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ match foo with
let range = getRangeBetween "keyword" headToken headToken
let info =
Trivia.Create(Keyword(headToken)) range
Trivia.Create (Keyword(headToken)) range
|> List.prependItem foundTrivia
getTriviaFromTokensThemSelves allTokens rest info
Expand Down
15 changes: 6 additions & 9 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2002,16 +2002,13 @@ and genExpr astContext synExpr ctx =
let sepSpaceAfterFunctionName =
let sepSpaceBasedOnSetting e =
match e with
| Paren _ -> sepSpace
| UppercaseSynExpr -> (fun ctx -> onlyIf ctx.Config.SpaceBeforeUppercaseInvocation sepSpace ctx)
| LowercaseSynExpr -> (fun ctx -> onlyIf ctx.Config.SpaceBeforeLowercaseInvocation sepSpace ctx)

match List.tryHead es with
| None ->
match e with
| Paren _ -> sepSpace
| _ -> sepSpaceBasedOnSetting e
| Some (SimpleExpr _) -> sepSpace
| _ -> sepSpaceBasedOnSetting e
match es with
| [] -> sepSpaceBasedOnSetting e
| _ -> sepSpace

let short =
genExpr astContext e
Expand Down Expand Up @@ -3215,8 +3212,8 @@ and genApp astContext e es ctx =
(fun ctx ->
match es with
| [] -> false
| [ h ]
| h :: _ -> addSpaceBeforeParensInFunCall e h ctx)
| [ h ] -> addSpaceBeforeParensInFunCall e h ctx
| _ -> true)
sepSpace
sepNone

Expand Down

0 comments on commit 6274245

Please sign in to comment.