Skip to content

Commit

Permalink
Fix unindented type abbreviation with line comment. Fixes #567 (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf authored Dec 19, 2019
1 parent 4913ed6 commit bf3bf95
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
15 changes: 14 additions & 1 deletion src/Fantomas.Tests/UnionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ type CustomerId = private | CustomerId of int
"""

[<Test>]
let ``Single case DU with member should be on a newline`` () =
let ``single case DU with member should be on a newline`` () =
formatSourceString false """
type CustomerId =
| CustomerId of int
Expand Down Expand Up @@ -217,4 +217,17 @@ type internal Foo = private | Bar
|> should equal """namespace meh
type internal Foo = private | Bar
"""

[<Test>]
let ``single case DU with comment above clause, 567`` () =
formatSourceString false """type 'a MyGenericType =
///
Foo
""" config
|> prepend newline
|> should equal """
type 'a MyGenericType =
///
Foo
"""
17 changes: 11 additions & 6 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1553,13 +1553,18 @@ and genTypeDefn astContext (TypeDef(ats, px, ao, tds, tcs, tdr, ms, s, preferPos

| Simple TDSRNone ->
typeName
| Simple(TDSRTypeAbbrev t) ->
typeName +> sepEq +> sepSpace
+> genTrivia tdr.Range
(genType astContext false t
+> ifElse (List.isEmpty ms) (!- "")
| Simple(TDSRTypeAbbrev t) ->
let genTypeAbbrev = genType astContext false t

let genMembers =
ifElse (List.isEmpty ms)
(!- "")
(indent ++ "with" +> indent +> genMemberDefnList { astContext with InterfaceRange = None } ms
+> unindent +> unindent))
+> unindent +> unindent)

let genTypeBody = autoIndentNlnByFuture (genTrivia tdr.Range genTypeAbbrev) +> genMembers

typeName +> sepEq +> sepSpace +> genTypeBody
| Simple(TDSRException(ExceptionDefRepr(ats, px, ao, uc))) ->
genExceptionBody astContext ats px ao uc
|> genTrivia tdr.Range
Expand Down

0 comments on commit bf3bf95

Please sign in to comment.