Skip to content

Commit

Permalink
Put arrow before type arg instead of on last line. Fixes #1637. (#1639)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Apr 13, 2021
1 parent f992dd7 commit 8b31264
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/Fantomas.Tests/LetBindingTests.fs
Expand Up @@ -1817,11 +1817,11 @@ type Viewport =
|> should
equal
"""
let useGeolocation : unit ->
{| latitude: float
longitude: float
loading: bool
error: obj option |} =
let useGeolocation : unit
-> {| latitude: float
longitude: float
loading: bool
error: obj option |} =
import "useGeolocation" "react-use"
type Viewport =
Expand Down
8 changes: 4 additions & 4 deletions src/Fantomas.Tests/SignatureTests.fs
Expand Up @@ -1455,10 +1455,10 @@ namespace Test
module OrderProcessing =
type ValidateOrder =
CheckProductCodeExists -> // dependency
CheckAddressExists -> // dependency
UnvalidatedOrder -> // input
Result<ValidatedOrder, ValidationError> // output (Result b/c one of deps returns a Result)
CheckProductCodeExists // dependency
-> CheckAddressExists // dependency
-> UnvalidatedOrder // input
-> Result<ValidatedOrder, ValidationError> // output (Result b/c one of deps returns a Result)
"""

[<Test>]
Expand Down
120 changes: 116 additions & 4 deletions src/Fantomas.Tests/TypeDeclarationTests.fs
Expand Up @@ -2711,8 +2711,120 @@ namespace Test
module OrderProcessing =
type ValidateOrder =
CheckProductCodeExists -> // dependency
CheckAddressExists -> // dependency
UnvalidatedOrder -> // input
Result<ValidatedOrder, ValidationError> // output (Result b/c one of deps returns a Result)
CheckProductCodeExists // dependency
-> CheckAddressExists // dependency
-> UnvalidatedOrder // input
-> Result<ValidatedOrder, ValidationError> // output (Result b/c one of deps returns a Result)
"""

[<Test>]
let ``generic type arguments in function invocation, 1637`` () =
formatSourceString
false
"""
[<NoEquality ; NoComparison>]
type Foo<'context, 'a> =
| Apply of ApplyCrate<'context, 'a>
and [<CustomEquality ; NoComparison>] Bar<'context, 'a> =
internal {
Hash : int
Foo : Foo<'a, 'b>
}
member this.InnerEquals<'innerContextLongLongLong, 'd, 'e> (a : Foo<'innerContextLongLongLong, 'd>) (b : Foo<'innerContext, 'd>) (cont : bool -> 'e) : 'e =
if a.Hash <> b.Hash then cont false
else
match a.Foo, b.Foo with
| Foo.Apply a, Foo.Apply b ->
a.Apply { new ApplyEval<_, _, _> with
member __.Eval<'bb> (a : Foo<'innerContextLongLongLong, 'bb -> 'b> * Foo<'innerContextLongLongLong, 'bb>) =
let (af, av) = a
b.Apply { new ApplyEval<_, _, _> with
member __.Eval<'cb> (b : Foo<'innerContextLongLongLong, 'cb -> 'b> * Foo<'innerContextLongLongLong, 'bc>) =
let (bf, bv) = b
if typeof<'bb> = typeof<'cb> then
let bv = unbox<Foo<'innerContextLongLongLong, 'bb>> bv
this.InnerEquals av bv (fun inner ->
if inner then
let bv = unbox<Foo<'innerContextLongLongLong, 'bb -> 'b>> bf
this.InnerEquals af bf cont
else cont false
)
else cont false
}
}
"""
{ config with
MaxLineLength = 100
SpaceBeforeUppercaseInvocation = true
SpaceBeforeClassConstructor = true
SpaceBeforeMember = true
SpaceBeforeColon = true
SpaceBeforeSemicolon = true
MultilineBlockBracketsOnSameColumn = true
KeepIfThenInSameLine = true
KeepIndentInBranch = true
AlignFunctionSignatureToIndentation = true
AlternativeLongMemberDefinitions = true
MultiLineLambdaClosingNewline = true }
|> prepend newline
|> should
equal
"""
[<NoEquality ; NoComparison>]
type Foo<'context, 'a> = Apply of ApplyCrate<'context, 'a>
and [<CustomEquality ; NoComparison>] Bar<'context, 'a> =
internal
{
Hash : int
Foo : Foo<'a, 'b>
}
member this.InnerEquals<'innerContextLongLongLong, 'd, 'e>
(a : Foo<'innerContextLongLongLong, 'd>)
(b : Foo<'innerContext, 'd>)
(cont : bool -> 'e)
: 'e
=
if a.Hash <> b.Hash then
cont false
else
match a.Foo, b.Foo with
| Foo.Apply a, Foo.Apply b ->
a.Apply
{ new ApplyEval<_, _, _> with
member __.Eval<'bb>
(a : Foo<'innerContextLongLongLong, 'bb -> 'b> * Foo<'innerContextLongLongLong, 'bb>)
=
let (af, av) = a
b.Apply
{ new ApplyEval<_, _, _> with
member __.Eval<'cb>
(b : Foo<'innerContextLongLongLong, 'cb -> 'b> * Foo<'innerContextLongLongLong, 'bc>)
=
let (bf, bv) = b
if typeof<'bb> = typeof<'cb> then
let bv =
unbox<Foo<'innerContextLongLongLong, 'bb>> bv
this.InnerEquals
av
bv
(fun inner ->
if inner then
let bv =
unbox<Foo<'innerContextLongLongLong, 'bb
-> 'b>>
bf
this.InnerEquals af bf cont
else
cont false
)
else
cont false
}
}
"""
6 changes: 3 additions & 3 deletions src/Fantomas/CodePrinter.fs
Expand Up @@ -4255,11 +4255,11 @@ and genType astContext outerBracket t =
| [] -> sepNone
| h :: rest ->
loop h
+> sepSpace
+> sepArrowFixed
+> indent
+> sepNln
+> col (sepSpace +> sepArrowFixed +> sepNln) rest loop
+> sepArrowFixed
+> sepSpace
+> col (sepNln +> sepArrowFixed +> sepSpace) rest loop
+> unindent

let genTs = expressionFitsOnRestOfLine short long
Expand Down

0 comments on commit 8b31264

Please sign in to comment.