Skip to content

Commit

Permalink
Preserve with get in signature files. Fixes #945 (#963)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Jul 11, 2020
1 parent 3c128a4 commit 311bff8
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
66 changes: 65 additions & 1 deletion src/Fantomas.Tests/SignatureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -598,4 +598,68 @@ namespace Blah
module Foo =
val inline sum: ('a -> ^value) -> 'a Foo -> ^value
when ^value: (static member (+): ^value * ^value -> ^value) and ^value: (static member Zero: ^value)
"""
"""

[<Test>]
let ``preserve with get property, 945`` () =
formatSourceString true """
namespace B
type Foo =
| Bar of int
member Item : unit -> int with get
""" { config with SpaceBeforeColon = true }
|> prepend newline
|> should equal """
namespace B
type Foo =
| Bar of int
member Item : unit -> int with get
"""

[<Test>]
let ``preserve with set property`` () =
formatSourceString true """
namespace B
type Foo =
member Item : int -> unit with set
""" { config with SpaceBeforeColon = true }
|> prepend newline
|> should equal """
namespace B
type Foo =
member Item : int -> unit with set
"""

[<Test>]
let ``preserve with get,set`` () =
formatSourceString true """
namespace B
type Foo =
member Item : int with get, set
""" { config with SpaceBeforeColon = true }
|> prepend newline
|> should equal """
namespace B
type Foo =
member Item : int with get, set
"""

[<Test>]
let ``with set after constraint`` () =
formatSourceString true """
namespace B
type Foo =
member Item : 't -> unit when 't : comparison with set
""" { config with SpaceBeforeColon = true }
|> prepend newline
|> should equal """
namespace B
type Foo =
member Item : 't -> unit when 't : comparison with set
"""
5 changes: 5 additions & 0 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2405,6 +2405,10 @@ and genMemberSig astContext node =
match node with
| MSMember(Val(ats, px, ao, s, t, vi, _, ValTyparDecls(tds, _, tcs)), mf) ->
let (FunType namedArgs) = (t, vi)
let isFunctionProperty =
match t with
| TFun _ -> true
| _ -> false
let sepColonX =
match tds with
| [] -> sepColon
Expand All @@ -2417,6 +2421,7 @@ and genMemberSig astContext node =
+> sepColonX
+> genTypeList astContext namedArgs
+> genConstraints astContext t
-- (genPropertyKind (not isFunctionProperty) mf.MemberKind)
+> unindent)

| MSInterface t -> !- "interface " +> genType astContext false t
Expand Down

0 comments on commit 311bff8

Please sign in to comment.