Skip to content

Commit 9059695

Browse files
authored
Don't collect triple slash comment in LineComments active pattern. Fixes #2152. (#2153)
1 parent 1531c68 commit 9059695

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Changelog
22

3-
## [Unreleased]
3+
## [4.7.3] - 2022-03-12
44

55
### Fixed
66
* Option parameter name is lost in tuple. [#2144](https://github.com/fsprojects/fantomas/issues/2144)
77
* Trivia between XmlDoc and member is not printed. [#2147](https://github.com/fsprojects/fantomas/issues/2147)
88
* Emit correct keyword for properties with both getter and setter specified [#2129](https://github.com/fsprojects/fantomas/issues/2129)
9+
* Duplicate ///-comments when immediately preceded by a //-comment. [#2152](https://github.com/fsprojects/fantomas/issues/2152)
910

1011
## [4.7.2] - 2022-03-11
1112

src/Fantomas.Tests/CommentTests.fs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,3 +1843,26 @@ module Example =
18431843
let dict2 =
18441844
ConcurrentDictionary< (* some comment 2 *) int64, ConcurrentDictionary< (* some comment 3 *) int32, unit>>()
18451845
"""
1846+
1847+
[<Test>]
1848+
let ``correctly collect a double slash comment before a xml doc comment, 2152`` () =
1849+
formatSourceString
1850+
false
1851+
"""
1852+
// Maybe computation expression builder, copied from ExtCore library
1853+
/// https://github.com/jack-pappas/ExtCore/blob/master/ExtCore/Control.fs
1854+
[<Sealed>]
1855+
type MaybeBuilder() = class end
1856+
"""
1857+
config
1858+
|> prepend newline
1859+
|> should
1860+
equal
1861+
"""
1862+
// Maybe computation expression builder, copied from ExtCore library
1863+
/// https://github.com/jack-pappas/ExtCore/blob/master/ExtCore/Control.fs
1864+
[<Sealed>]
1865+
type MaybeBuilder() =
1866+
class
1867+
end
1868+
"""

src/Fantomas/TokenParser.fs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,11 @@ let private (|LineComments|_|) (tokens: Token list) =
692692
(finalContinuation: Token list -> Token list)
693693
: Token list * Token list =
694694
match tokens with
695+
// When collecting a line comment, stop if we move from a double slash to a triple slash comment.
696+
| LineCommentToken { Content = "///"
697+
LineNumber = tripleLn } :: _ when tripleLn = lastLineNumber + 1 ->
698+
finalContinuation [], tokens
699+
// Collect comment tokens when the current line is underneath the previous one.
695700
| LineCommentToken lc :: rest when (lc.LineNumber <= lastLineNumber + 1) ->
696701
collect rest lc.LineNumber (fun commentTokens -> lc :: commentTokens |> finalContinuation)
697702
| _ -> finalContinuation [], tokens
@@ -812,11 +817,7 @@ let rec private getTriviaFromTokensThemSelves
812817
=
813818
match tokens with
814819
// Skip triple slash comments
815-
| TripleSlashLineComment (rest) ->
816-
getTriviaFromTokensThemSelves mkRange lastButOneNonWhiteSpaceToken lastNonWhiteSpaceToken rest foundTrivia
817-
818-
// Skip triple slash comments
819-
| LineComments ({ Content = "///" } :: _, rest) ->
820+
| TripleSlashLineComment rest ->
820821
getTriviaFromTokensThemSelves mkRange lastButOneNonWhiteSpaceToken lastNonWhiteSpaceToken rest foundTrivia
821822

822823
| LineComments ({ LineNumber = headLineNumber } :: _ as commentTokens, rest) ->

0 commit comments

Comments
 (0)