Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #363 #367

Merged
merged 2 commits into from
Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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