Skip to content

Commit

Permalink
Combine KeepIndentInBranch and MultiLineLambdaClosingNewline. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed May 19, 2021
1 parent c3f345b commit c3dea78
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 4 deletions.
100 changes: 100 additions & 0 deletions src/Fantomas.Tests/KeepIndentInBranchTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1587,3 +1587,103 @@ let x =
let ipv4 = string result.["ipv4"]
None
"""

[<Test>]
let ``combination with MultiLineLambdaClosingNewline, 1715`` () =
formatSourceString
false
"""
module Foo =
let bar () =
let baz =
[]
|> List.filter (fun ref ->
if ref.Type <> "h" then false
else
let m = regex.Match ref.To
m.Success && things |> Set.contains (m.Groups.[1].ToString ())
)
0
"""
{ config with
SpaceBeforeUppercaseInvocation = true
SpaceBeforeClassConstructor = true
SpaceBeforeMember = true
SpaceBeforeColon = true
SpaceBeforeSemicolon = true
AlignFunctionSignatureToIndentation = true
AlternativeLongMemberDefinitions = true
MultiLineLambdaClosingNewline = true
KeepIndentInBranch = true }
|> prepend newline
|> should
equal
"""
module Foo =
let bar () =
let baz =
[]
|> List.filter (fun ref ->
if ref.Type <> "h" then
false
else
let m = regex.Match ref.To
m.Success
&& things |> Set.contains (m.Groups.[1].ToString ())
)
0
"""

[<Test>]
let ``combination with MultiLineLambdaClosingNewline, multiple params`` () =
formatSourceString
false
"""
module Foo =
let bar () =
let baz =
[]
|> List.filterWith X (fun ref ->
if ref.Type <> "h" then false
else
let m = regex.Match ref.To
m.Success && things |> Set.contains (m.Groups.[1].ToString ())
)
0
"""
{ config with
SpaceBeforeUppercaseInvocation = true
SpaceBeforeClassConstructor = true
SpaceBeforeMember = true
SpaceBeforeColon = true
SpaceBeforeSemicolon = true
AlignFunctionSignatureToIndentation = true
AlternativeLongMemberDefinitions = true
MultiLineLambdaClosingNewline = true
KeepIndentInBranch = true }
|> prepend newline
|> should
equal
"""
module Foo =
let bar () =
let baz =
[]
|> List.filterWith
X
(fun ref ->
if ref.Type <> "h" then
false
else
let m = regex.Match ref.To
m.Success
&& things |> Set.contains (m.Groups.[1].ToString ())
)
0
"""
9 changes: 5 additions & 4 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3198,9 +3198,9 @@ and genApp astContext e es ctx =

let genExprAfterArrow (e: SynExpr) ctx =
if Option.isSome (findTriviaTokenFromName RARROW e.Range ctx) then
genExpr astContext e ctx
genExprKeepIndentInBranch astContext e ctx
else
autoNlnIfExpressionExceedsPageWidth (genExpr astContext e) ctx
autoNlnIfExpressionExceedsPageWidth (genExprKeepIndentInBranch astContext e) ctx

leadingExpressionIsMultiline
(sepOpenTFor lpr -- "fun "
Expand Down Expand Up @@ -3234,8 +3234,9 @@ and genApp astContext e es ctx =

let genExprAfterArrow (e: SynExpr) ctx =
match findTriviaTokenFromName RARROW e.Range ctx with
| Some _ -> genExpr astContext e ctx
| None -> autoNlnIfExpressionExceedsPageWidth (genExpr astContext e) ctx
| Some _ -> genExprKeepIndentInBranch astContext e ctx
| None ->
autoNlnIfExpressionExceedsPageWidth (genExprKeepIndentInBranch astContext e) ctx

sepOpenTFor lpr -- "fun "
+> pats
Expand Down

0 comments on commit c3dea78

Please sign in to comment.