From 2f9a9b0a28a19ab9264f83d51005633af04b5f4a Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 13 Sep 2019 09:46:09 +0200 Subject: [PATCH] Improve Fabulous views by adding newline after equals when futureNln --- src/Fantomas.Tests/ElmishTests.fs | 24 +++++++++++++++++++ src/Fantomas.Tests/Fantomas.Tests.fsproj | 1 + src/Fantomas.Tests/FunctionDefinitionTests.fs | 3 ++- src/Fantomas.Tests/TypeDeclarationTests.fs | 6 ++--- src/Fantomas/CodePrinter.fs | 11 ++++++++- 5 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 src/Fantomas.Tests/ElmishTests.fs diff --git a/src/Fantomas.Tests/ElmishTests.fs b/src/Fantomas.Tests/ElmishTests.fs new file mode 100644 index 0000000000..998875a356 --- /dev/null +++ b/src/Fantomas.Tests/ElmishTests.fs @@ -0,0 +1,24 @@ +module Fantomas.Tests.ElmishTests + +open NUnit.Framework +open FsUnit +open Fantomas.Tests.TestHelper + +[] +let ``long named arguments should go on newline`` () = + formatSourceString false """let view (model: Model) dispatch = + View.ContentPage( + appearing=(fun () -> dispatch PageAppearing), + title=model.Planet.Info.Name, + backgroundColor=Color.Black, + content=["....long line....................................................................................................."] + ) +""" config + |> prepend newline + |> should equal """ +let view (model: Model) dispatch = + View.ContentPage + (appearing = (fun () -> dispatch PageAppearing), title = model.Planet.Info.Name, backgroundColor = Color.Black, + content = + [ "....long line....................................................................................................." ]) +""" \ No newline at end of file diff --git a/src/Fantomas.Tests/Fantomas.Tests.fsproj b/src/Fantomas.Tests/Fantomas.Tests.fsproj index d71af32bd5..a4e44f58ec 100644 --- a/src/Fantomas.Tests/Fantomas.Tests.fsproj +++ b/src/Fantomas.Tests/Fantomas.Tests.fsproj @@ -54,6 +54,7 @@ + diff --git a/src/Fantomas.Tests/FunctionDefinitionTests.fs b/src/Fantomas.Tests/FunctionDefinitionTests.fs index 0c3ae65bf0..154b361da4 100644 --- a/src/Fantomas.Tests/FunctionDefinitionTests.fs +++ b/src/Fantomas.Tests/FunctionDefinitionTests.fs @@ -254,7 +254,8 @@ open Accessibility [] extern int AccessibleChildren(IAccessible paccContainer, int iChildStart, int cChildren, [] System.Object [] rgvarChildren, int* pcObtained) + SizeParamIndex = + 4s)>] System.Object [] rgvarChildren, int* pcObtained) """ [] diff --git a/src/Fantomas.Tests/TypeDeclarationTests.fs b/src/Fantomas.Tests/TypeDeclarationTests.fs index a515743e3d..392e029914 100644 --- a/src/Fantomas.Tests/TypeDeclarationTests.fs +++ b/src/Fantomas.Tests/TypeDeclarationTests.fs @@ -783,9 +783,9 @@ let x = let x = JobCollectionCreateParameters (Label = "Test", - IntrinsicSettings = JobCollectionIntrinsicSettings - (Plan = JobCollectionPlan.Standard, - Quota = new JobCollectionQuota(MaxJobCount = Nullable(50)))) + IntrinsicSettings = + JobCollectionIntrinsicSettings + (Plan = JobCollectionPlan.Standard, Quota = new JobCollectionQuota(MaxJobCount = Nullable(50)))) """ [] diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 31dff7af48..2bf45acebd 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -1139,7 +1139,16 @@ and genLetOrUseList astContext expr = and genInfixApps astContext hasNewLine synExprs = match synExprs with | (s, opE, e)::es when (NoBreakInfixOps.Contains s) -> - (sepSpace +> tok opE.Range s +> sepSpace +> genExpr astContext e) + (sepSpace +> tok opE.Range s + +> (fun ctx -> + let futureNln = futureNlnCheck (genExpr astContext e) ctx + let genExpr = + match opE with + | SynExpr.Ident(Ident("op_Equality")) when(futureNln) -> + indent +> sepNln +> genExpr astContext e +> unindent + | _ -> + sepSpace +> genExpr astContext e + genExpr ctx)) +> genInfixApps astContext (hasNewLine || checkNewLine e es) es | (s, opE, e)::es when(hasNewLine) -> (sepNln +> tok opE.Range s +> sepSpace +> genExpr astContext e)