Skip to content

Commit

Permalink
Print members after explicit class/end. Fixes #1940. (#2008)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf authored Jan 7, 2022
1 parent 6ac445a commit 6edcf90
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/Fantomas.Tests/ClassTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -968,3 +968,53 @@ type public DerivedExceptionWithLongNaaaaaaaaameException
override this.SomeMethod() = ()
"""

[<Test>]
let ``explicit class/end/with, 1940`` () =
formatSourceString
false
"""
type C() =
class
member x.P = 1
end
with
member _.Run() = 1
"""
config
|> prepend newline
|> should
equal
"""
type C() =
class
member x.P = 1
end
member _.Run() = 1
"""

[<Test>]
let ``explicit class/end with members, idempotent`` () =
formatSourceString
false
"""
type C() =
class
member x.P = 1
end
member _.Run() = 1
"""
config
|> prepend newline
|> should
equal
"""
type C() =
class
member x.P = 1
end
member _.Run() = 1
"""
14 changes: 14 additions & 0 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3701,6 +3701,20 @@ and genTypeDefn
+> genMemberDefnList astContext others
+> unindent
++ "end"
+> (fun ctx ->
match ms with
| [] -> ctx
| h :: _ ->
let attrs =
getRangesFromAttributesFromSynMemberDefinition h

let sepNlnBeforeMember =
sepNlnConsideringTriviaContentBeforeWithAttributesFor (synMemberDefnToFsAstType h) h.Range attrs

(sepNln
+> sepNlnBeforeMember
+> genMemberDefnList astContext ms)
ctx)
+> unindent

| ObjectModel (TCSimple TCStruct as tdk, MemberDefnList (impCtor, others), _) ->
Expand Down

0 comments on commit 6edcf90

Please sign in to comment.