Skip to content

Commit

Permalink
Don't collect triple slash comment in LineComments active pattern. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Mar 12, 2022
1 parent 1531c68 commit f12ce8e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Changelog

## [Unreleased]
## [4.7.3] - 2022-03-12

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

## [4.7.2] - 2022-03-11

Expand Down
23 changes: 23 additions & 0 deletions src/Fantomas.Tests/CommentTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1843,3 +1843,26 @@ module Example =
let dict2 =
ConcurrentDictionary< (* some comment 2 *) int64, ConcurrentDictionary< (* some comment 3 *) int32, unit>>()
"""

[<Test>]
let ``correctly collect a double slash comment before a xml doc comment, 2152`` () =
formatSourceString
false
"""
// Maybe computation expression builder, copied from ExtCore library
/// https://github.com/jack-pappas/ExtCore/blob/master/ExtCore/Control.fs
[<Sealed>]
type MaybeBuilder() = class end
"""
config
|> prepend newline
|> should
equal
"""
// Maybe computation expression builder, copied from ExtCore library
/// https://github.com/jack-pappas/ExtCore/blob/master/ExtCore/Control.fs
[<Sealed>]
type MaybeBuilder() =
class
end
"""
11 changes: 6 additions & 5 deletions src/Fantomas/TokenParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,11 @@ let private (|LineComments|_|) (tokens: Token list) =
(finalContinuation: Token list -> Token list)
: Token list * Token list =
match tokens with
// When collecting a line comment, stop if we move from a double slash to a triple slash comment.
| LineCommentToken { Content = "///"
LineNumber = tripleLn } :: _ when tripleLn = lastLineNumber + 1 ->
finalContinuation [], tokens
// Collect comment tokens when the current line is underneath the previous one.
| LineCommentToken lc :: rest when (lc.LineNumber <= lastLineNumber + 1) ->
collect rest lc.LineNumber (fun commentTokens -> lc :: commentTokens |> finalContinuation)
| _ -> finalContinuation [], tokens
Expand Down Expand Up @@ -812,11 +817,7 @@ let rec private getTriviaFromTokensThemSelves
=
match tokens with
// Skip triple slash comments
| TripleSlashLineComment (rest) ->
getTriviaFromTokensThemSelves mkRange lastButOneNonWhiteSpaceToken lastNonWhiteSpaceToken rest foundTrivia

// Skip triple slash comments
| LineComments ({ Content = "///" } :: _, rest) ->
| TripleSlashLineComment rest ->
getTriviaFromTokensThemSelves mkRange lastButOneNonWhiteSpaceToken lastNonWhiteSpaceToken rest foundTrivia

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

0 comments on commit f12ce8e

Please sign in to comment.