Skip to content

Commit

Permalink
Enum cases comments (#578)
Browse files Browse the repository at this point in the history
* Docs - default pageWidth is 120

* Generate Trivia for Enum cases - fixes #572

* Change test name and move it to the bottom
  • Loading branch information
theimowski authored and nojaf committed Nov 28, 2019
1 parent 0f27ccf commit 9f349df
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ To illustrate, here is a code fragment with `--indent 2`:
```
- `--pageWidth <number>`: `number` has to be an integer greater or equal to 60.
This preference sets the column where we break F# constructs into new lines.
The default value is 80. To see its effects, please take a look at some [output files](tests/stackexchange_output) with `--pageWidth 90` preference.
The default value is 120. To see its effects, please take a look at some [output files](tests/stackexchange_output) with `--pageWidth 90` preference.

- `--semicolonEOL`: add semicolons at the end of lines e.g.

Expand Down
33 changes: 33 additions & 0 deletions src/Fantomas.Tests/CommentTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -712,4 +712,37 @@ if true then
1
else //comment
0
"""

[<Test>]
let ``comments for enum cases, 572``() =
formatSourceString false """type A =
/// Doc for CaseA
| CaseA = 0
/// Doc for CaseB
| CaseB = 1
/// Doc for CaseC
| CaseC = 2""" config
|> should equal """type A =
/// Doc for CaseA
| CaseA = 0
/// Doc for CaseB
| CaseB = 1
/// Doc for CaseC
| CaseC = 2
"""
formatSourceString false """type A =
// Comment for CaseA
| CaseA = 0
// Comment for CaseB
| CaseB = 1
// Comment for CaseC
| CaseC = 2""" config
|> should equal """type A =
// Comment for CaseA
| CaseA = 0
// Comment for CaseB
| CaseB = 1
// Comment for CaseC
| CaseC = 2
"""
1 change: 1 addition & 0 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,7 @@ and genEnumCase astContext (EnumCase(ats, px, _, (_,r)) as node) =
!- ident.idText +> !- " = " +> genConst c r

genPreXmlDoc px
+> genTriviaBeforeClausePipe node.Range
+> ifElse astContext.HasVerticalBar sepBar sepNone
+> genOnelinerAttributes astContext ats
+> genCase
Expand Down

0 comments on commit 9f349df

Please sign in to comment.