Skip to content

Commit

Permalink
Put multiline when condition on the next line. Fixes fsprojects#1320.
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Dec 22, 2020
1 parent 443dbcb commit 5a33609
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
33 changes: 33 additions & 0 deletions src/Fantomas.Tests/PatternMatchingTests.fs
Expand Up @@ -1060,3 +1060,36 @@ let rec (|DoExprAttributesL|_|) =
| Attributes _ as x :: ys -> Some([ x ], ys)
| _ -> None
"""

[<Test>]
let ``multiline when condition, 1320`` () =
formatSourceString
false
"""
module Foo =
module Bar =
let buildUsage argInfos =
match v.IsMember, v.IsInstanceMember, v.LogicalName, v.DisplayName with
// Ordinary functions or values
| false, _, _, name when
not (hasAttribute<RequireQualifiedAccessAttribute> v.ApparentEnclosingEntity.Attributes) ->
name + " " + parArgs
// Ordinary static members or things (?) that require fully qualified access
| _, _, _, name -> name + parArgs
"""
config
|> prepend newline
|> should
equal
"""
module Foo =
module Bar =
let buildUsage argInfos =
match v.IsMember, v.IsInstanceMember, v.LogicalName, v.DisplayName with
// Ordinary functions or values
| false, _, _, name when
not (hasAttribute<RequireQualifiedAccessAttribute> v.ApparentEnclosingEntity.Attributes) ->
name + " " + parArgs
// Ordinary static members or things (?) that require fully qualified access
| _, _, _, name -> name + parArgs
"""
6 changes: 5 additions & 1 deletion src/Fantomas/CodePrinter.fs
Expand Up @@ -4230,7 +4230,11 @@ and genClause astContext hasBar (Clause (p, e, eo)) =
mkRange "arrowRange" p.Range.End e.Range.Start

let body =
optPre (!- " when ") sepNone eo (genExpr astContext)
optPre
(!- " when")
sepNone
eo
(fun e -> sepSpaceOrIndentAndNlnIfExpressionExceedsPageWidth (genExpr astContext e))
+> sepArrow
+> leaveNodeTokenByName arrowRange RARROW
+> clauseBody e
Expand Down

0 comments on commit 5a33609

Please sign in to comment.