Skip to content

Commit

Permalink
Fix for additional newline. fsprojects#360
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Nov 21, 2018
1 parent 9b6fb00 commit 6891b14
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
21 changes: 21 additions & 0 deletions src/Fantomas.Tests/PreserveEOLTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -469,3 +469,24 @@ let x = 1
let y = 2
#endif
"""

[<Test>]
let ``single line comments at end of line should not added additional newline`` () =
let config = { config with PageWidth = 80 }

formatSourceString false """
type QueryOption =
| FixedQuery of string // xpath
| KeywordSearch of string // keyword
type MessageTypeQueryMeta =
{ Options: QueryOption list }
""" config
|> should equal """
type QueryOption =
| FixedQuery of string // xpath
| KeywordSearch of string // keyword
type MessageTypeQueryMeta =
{ Options : QueryOption list }
"""
10 changes: 7 additions & 3 deletions src/Fantomas/CodeFormatter.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ fsi.AddPrinter (fun (p : pos) -> p.ToString())
fsi.AddPrinter (fun (r : range) -> r.ToString())

"""
type T() =
let x = 123
// override private x.ToString() = ""
type QueryOption =
| FixedQuery of string // xpath
| KeywordSearch of string // keyword
type MessageTypeQueryMeta =
{ Options: QueryOption list }
"""
|> formatSrc

Expand Down
5 changes: 3 additions & 2 deletions src/Fantomas/TokenMatcher.fs
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,9 @@ let integrateComments isPreserveEOL compilationDefines (originalText : string) (
| Space _ :: (EOL, newTokText) :: moreNewTokens | (EOL, newTokText) :: moreNewTokens ->
addText " "
for x in commentTokensText do addText x
Debug.WriteLine "emitting newline for end of sticky-to-left comment"
addText newTokText
if not isPreserveEOL then
Debug.WriteLine "emitting newline for end of sticky-to-left comment"
addText newTokText
loop moreOrigTokens moreNewTokens
// Otherwise, skip a whitespace token and maintain the indentation
| Space _ :: moreNewTokens | moreNewTokens ->
Expand Down

0 comments on commit 6891b14

Please sign in to comment.