Skip to content

Commit

Permalink
Print trivia after short record type declaration. Fixes #774 (#775)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Apr 24, 2020
1 parent fe5510e commit a9542bc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/Fantomas.Tests/RecordTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -882,4 +882,31 @@ let meh =
{ // this comment right
Name = "FOO"
Level = 78 }
"""

[<Test>]
let ``line comment after short syntax record type, 774`` () =
formatSourceString false """type FormatConfig = {
PageWidth: int
Indent: int } // The number of spaces
""" config
|> should equal """type FormatConfig = { PageWidth: int; Indent: int } // The number of spaces
"""

[<Test>]
let ``line comment after short record instance syntax`` () =
formatSourceString false """let formatConfig = {
PageWidth = 70
Indent = 8 } // The number of spaces
""" config
|> should equal """let formatConfig = { PageWidth = 70; Indent = 8 } // The number of spaces
"""

[<Test>]
let ``line comment after short anonymous record instance syntax`` () =
formatSourceString false """let formatConfig = {|
PageWidth = 70
Indent = 8 |} // The number of spaces
""" config
|> should equal """let formatConfig = {| PageWidth = 70; Indent = 8 |} // The number of spaces
"""
5 changes: 4 additions & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,10 @@ and genTypeDefn astContext (TypeDef(ats, px, ao, tds, tcs, tdr, ms, s, preferPos

let bodyExpr ctx =
if (List.isEmpty ms) then
(isShortExpression ctx.Config.MaxRecordWidth shortExpression multilineExpression) ctx
(isShortExpression ctx.Config.MaxRecordWidth shortExpression multilineExpression
+> leaveNode tdr.Range // this will only print something when there is trivia after } in the short expression
// Yet it cannot be part of the short expression otherwise the multiline expression would be triggered unwillingly.
) ctx
else
multilineExpression ctx

Expand Down

0 comments on commit a9542bc

Please sign in to comment.