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

Added multiline upcast/downcast formatting. #1210

Merged
merged 1 commit into from
Oct 30, 2020
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
53 changes: 53 additions & 0 deletions src/Fantomas.Tests/CastTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module Fantomas.Tests.CastTests

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

[<Test>]
let ``multiline downcast expression, `` () =
formatSourceString false """
longMethodName
longArgument
longArgument2
:?> List<bool>
"""
{ config with
MaxLineLength = 30
SpaceBeforeUppercaseInvocation = true
SpaceBeforeColon = true
SpaceBeforeSemicolon = true
AlignFunctionSignatureToIndentation = true
AlternativeLongMemberDefinitions = true
DisableElmishSyntax = true }
|> prepend newline
|> should equal """
longMethodName
longArgument
longArgument2
:?> List<bool>
"""

[<Test>]
let ``multiline upcast expression, `` () =
formatSourceString false """
longMethodName
longArgument
longArgument2
:> List<bool>
"""
{ config with
MaxLineLength = 30
SpaceBeforeUppercaseInvocation = true
SpaceBeforeColon = true
SpaceBeforeSemicolon = true
AlignFunctionSignatureToIndentation = true
AlternativeLongMemberDefinitions = true
DisableElmishSyntax = true }
|> prepend newline
|> should equal """
longMethodName
longArgument
longArgument2
:> List<bool>
"""
3 changes: 2 additions & 1 deletion src/Fantomas.Tests/ComputationExpressionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,8 @@ let sendPushNotifications =
subscriptions
s.Origin
s.Endpoint
} :> Task)
}
:> Task)
|> Task.WhenAll)
"""

Expand Down
1 change: 1 addition & 0 deletions src/Fantomas.Tests/Fantomas.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<Compile Include="NumberOfItemsMultilineInfixOperatorExpressionTests.fs" />
<Compile Include="SynExprNewTests.fs" />
<Compile Include="DisableElmishTests.fs" />
<Compile Include="CastTests.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fantomas.Extras\Fantomas.Extras.fsproj" />
Expand Down
22 changes: 18 additions & 4 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1357,11 +1357,25 @@ and genExpr astContext synExpr ctx =
+> ifElse (hasParenthesis e) sepNone sepSpace
+> genExpr astContext e
| TypedExpr (Downcast, e, t) ->
genExpr astContext e -- " :?> "
+> genType astContext false t
let shortExpr =
genExpr astContext e -- " :?> "
+> genType astContext false t

let longExpr =
genExpr astContext e +> sepNln -- ":?> "
+> genType astContext false t

expressionFitsOnRestOfLine shortExpr longExpr
| TypedExpr (Upcast, e, t) ->
genExpr astContext e -- " :> "
+> genType astContext false t
let shortExpr =
genExpr astContext e -- " :> "
+> genType astContext false t

let longExpr =
genExpr astContext e +> sepNln -- ":> "
+> genType astContext false t

expressionFitsOnRestOfLine shortExpr longExpr
| TypedExpr (Typed, e, t) ->
genExpr astContext e
+> sepColon
Expand Down