Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored fix for #383. #395

Merged
merged 1 commit into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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