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 <[email protected]>
  • Loading branch information
knocte and janus authored Feb 13, 2022
1 parent 2f05dae commit 533a141
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
19 changes: 19 additions & 0 deletions src/Fantomas.Tests/AppTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -779,3 +779,22 @@ let makeStreamReader x y = new StreamReader(arg1=x, arg2=y)"""
"""
let makeStreamReader x y = new StreamReader(arg1 = x, arg2 = y)
"""

[<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 @@ -2000,16 +2000,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 533a141

Please sign in to comment.