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

Preserve with get in signature files #963

Merged
merged 1 commit into from
Jul 11, 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
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