Skip to content

Commit

Permalink
Improve Fabulous views by adding newline after equals when futureNln
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Sep 13, 2019
1 parent df6f31d commit 2f9a9b0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
24 changes: 24 additions & 0 deletions src/Fantomas.Tests/ElmishTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Fantomas.Tests.ElmishTests

open NUnit.Framework
open FsUnit
open Fantomas.Tests.TestHelper

[<Test>]
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....................................................................................................." ])
"""
1 change: 1 addition & 0 deletions src/Fantomas.Tests/Fantomas.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<Compile Include="FSharpScriptTests.fs" />
<Compile Include="TupleTests.fs" />
<Compile Include="KeepNewlineAfterTests.fs" />
<Compile Include="ElmishTests.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fantomas\Fantomas.fsproj" />
Expand Down
3 changes: 2 additions & 1 deletion src/Fantomas.Tests/FunctionDefinitionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ open Accessibility
[<DllImport("oleacc.dll")>]
extern int AccessibleChildren(IAccessible paccContainer, int iChildStart, int cChildren, [<Out; MarshalAs(UnmanagedType.LPArray,
SizeParamIndex = 4s)>] System.Object [] rgvarChildren, int* pcObtained)
SizeParamIndex =
4s)>] System.Object [] rgvarChildren, int* pcObtained)
"""

[<Test>]
Expand Down
6 changes: 3 additions & 3 deletions src/Fantomas.Tests/TypeDeclarationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
"""

[<Test>]
Expand Down
11 changes: 10 additions & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2f9a9b0

Please sign in to comment.