Skip to content

Commit

Permalink
Print out type extension members. Fixes fsprojects#413
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Jan 3, 2020
1 parent 28bf163 commit c7997bc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
21 changes: 21 additions & 0 deletions src/Fantomas.Tests/SignatureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -456,4 +456,25 @@ module Teq =
/// returns the type equality for the corresponding pair types.
val pair<'fst1, 'snd1, 'fst2, 'snd2> : Teq<'fst1, 'fst2>
-> Teq<'snd1, 'snd2> -> Teq<'fst1 * 'snd1, 'fst2 * 'snd2>
"""

[<Test>]
let ``intrinsic type extension member signature, 413`` () =
formatSourceString true """namespace ExtensionParts
type T =
new: unit -> T
type T with
member Foo: int
""" config
|> prepend newline
|> should equal """
namespace ExtensionParts
type T =
new: unit -> T
type T with
member Foo: int
"""
14 changes: 10 additions & 4 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ and genSigModuleDecl astContext node =
| SigOpen(s) ->
!- (sprintf "open %s" s)
| SigTypes(t::ts) ->
let tsx = ts

genSigTypeDefn { astContext with IsFirstChild = true } t
+> colPre (rep 2 sepNln) (rep 2 sepNln) ts (genSigTypeDefn { astContext with IsFirstChild = false })
| md ->
Expand Down Expand Up @@ -1716,8 +1718,12 @@ and genSigTypeDefn astContext (SigTypeDef(ats, px, ao, tds, tcs, tdr, ms, s, pre
+> colPre sepNln sepNln ms (genMemberSig astContext)
+> unindent

| SigSimple TDSRNone ->
typeName
| SigSimple TDSRNone ->
let genMembers =
match ms with
| [] -> sepNone
| _ -> !- " with" +> indent +> sepNln +> col sepNln ms (genMemberSig astContext) +> unindent
typeName +> genMembers
| SigSimple(TDSRTypeAbbrev t) ->
let genTypeAbbrev =
let needsParenthesis =
Expand Down Expand Up @@ -1746,8 +1752,8 @@ and genSigTypeDefn astContext (SigTypeDef(ats, px, ao, tds, tcs, tdr, ms, s, pre

| SigObjectModel(TCDelegate(FunType ts), _) ->
typeName +> sepEq +> sepSpace -- "delegate of " +> genTypeList astContext ts
| SigObjectModel(_, mds) ->
typeName +> sepEq +> indent +> sepNln
| SigObjectModel(_, mds) ->
typeName +> sepEq +> indent +> sepNln
+> col sepNln mds (genMemberSig astContext) +> unindent

| SigExceptionRepr(SigExceptionDefRepr(ats, px, ao, uc)) ->
Expand Down

0 comments on commit c7997bc

Please sign in to comment.