Skip to content

Commit

Permalink
Refactored fix for fsprojects#383.
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Jan 22, 2019
1 parent 782ebb5 commit 21c7bd9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
Binary file modified .paket/paket.exe
Binary file not shown.
5 changes: 2 additions & 3 deletions src/Fantomas.Tests/PatternMatchingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ let update msg model =
"""

[<Test>]
let ``updated record with function call should be on newline, even though short`` () =
let ``updated record with function call remains be on same line, because short enough`` () =
formatSourceString false """
let x = { Value = 36 }.Times(9)
Expand All @@ -426,6 +426,5 @@ match b with
let x = { Value = 36 }.Times(9)
match b with
| _ ->
{ Value = 42 }.Times(8)
| _ -> { Value = 42 }.Times(8)
"""
16 changes: 5 additions & 11 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ and breakNlnOrAddSpace astContext brk e =
(indent +> autoNlnOrSpace (genExpr astContext e) +> unindent)

/// Preserve a break even if the expression is a one-liner
and preserveBreakNln astContext e ctx =
breakNln astContext (checkPreserveBreakForExpr e ctx) e ctx
and preserveBreakNln astContext e ctx =
let brk = checkPreserveBreakForExpr e ctx || futureNlnCheck (genExpr astContext e) sepNone ctx
breakNln astContext brk e ctx

and preserveBreakNlnOrAddSpace astContext e ctx =
breakNlnOrAddSpace astContext (checkPreserveBreakForExpr e ctx) e ctx
Expand Down Expand Up @@ -1099,15 +1100,8 @@ and genInterfaceImpl astContext (InterfaceImpl(t, bs, range)) =
+> indent +> sepNln +> genMemberBindingList { astContext with InterfaceRange = Some range } bs +> unindent

and genClause astContext hasBar (Clause(p, e, eo)) =
ifElse hasBar sepBar sepNone +> genPat astContext p
+> optPre (!- " when ") sepNone eo (genExpr astContext) +> sepArrow +> (fun ctx ->
let alreadyMultiline = checkPreserveBreakForExpr e ctx
match alreadyMultiline, e with
| false, SynExpr.App(_,_,SynExpr.DotGet(SynExpr.Record(_, copyInfo,recordFields,_), _, LongIdentWithDots(lid), range),_,_) ->
(breakNln astContext true e) ctx
| _ ->
(breakNln astContext alreadyMultiline e) ctx
)
ifElse hasBar sepBar sepNone +> genPat astContext p
+> optPre (!- " when ") sepNone eo (genExpr astContext) +> sepArrow +> preserveBreakNln astContext e

/// Each multiline member definition has a pre and post new line.
and genMemberDefnList astContext (*(interfaceRange:Microsoft.FSharp.Compiler.Range.range)*) = function
Expand Down

0 comments on commit 21c7bd9

Please sign in to comment.