Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf authored Nov 26, 2018
1 parent 289a318 commit 203eb7e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
Binary file modified .paket/paket.exe
Binary file not shown.
35 changes: 35 additions & 0 deletions src/Fantomas.Tests/PreserveEOLTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -516,4 +516,39 @@ let config =
let config =
[("n", "1")
("d", "2")]
"""

[<Test>]
let ``ending with multiline comment should not introduce additional newline`` () =
formatSourceString false """
#r "System.Xml.Linq"
open System.Xml.Linq
open System.Xml.XPath
let xml = "<a>1</a>"
(*
Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam
*)
""" config
|> should equal """
#r "System.Xml.Linq"
open System.Xml.Linq
open System.Xml.XPath
let xml = "<a>1</a>"
(*
Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam
*)
"""
11 changes: 4 additions & 7 deletions src/Fantomas/TokenMatcher.fs
Original file line number Diff line number Diff line change
Expand Up @@ -750,16 +750,13 @@ let integrateComments (config:Fantomas.FormatConfig.FormatConfig) compilationDef
loop origTokens moreNewTokens

// Process the last line or block comments
| (LineCommentChunk false (commentTokensText, moreOrigTokens)), [] when (isPreserveEOL) ->
Debug.WriteLine("injecting the last line comment '{0}'", String.concat "" commentTokensText |> box)
for x in commentTokensText do addText x
loop moreOrigTokens newTokens

| (LineCommentChunk false (commentTokensText, moreOrigTokens)), []
| (BlockCommentChunk (commentTokensText, moreOrigTokens)), [] ->
Debug.WriteLine("injecting the last line or block comment '{0}'", String.concat "" commentTokensText |> box)
// Until block comments can't have new line in the beginning, add two consecutive new lines
addText Environment.NewLine
if not isPreserveEOL then
// Until block comments can't have new line in the beginning, add two consecutive new lines
addText Environment.NewLine

for x in commentTokensText do addText x
loop moreOrigTokens newTokens

Expand Down

0 comments on commit 203eb7e

Please sign in to comment.