diff --git a/src/Fantomas.Tests/CommentTests.fs b/src/Fantomas.Tests/CommentTests.fs index 90d18c43e3..d35de6e808 100644 --- a/src/Fantomas.Tests/CommentTests.fs +++ b/src/Fantomas.Tests/CommentTests.fs @@ -860,4 +860,46 @@ type LongIdentWithDots = /// more freedom about typechecking these expressions. /// LongIdent can be empty list - it is used to denote that name of some AST element is absent (i.e. empty type name in inherit) type LongIdentWithDots = LongIdentWithDots of id: LongIdent * dotms: range list -""" \ No newline at end of file +""" + +[] +let ``newline between comments should lead to individual comments, 920`` () = + formatSourceString false """ +[] +type IExports = + abstract DataSet: DataSetStatic + abstract DataView: DataViewStatic + abstract Graph2d: Graph2dStatic + abstract Timeline: TimelineStatic + // abstract Timeline: TimelineStaticStatic + abstract Network: NetworkStatic + +// type [] MomentConstructor1 = +// [] abstract Invoke: ?inp: MomentInput * ?format: MomentFormatSpecification * ?strict: bool -> Moment + +// type [] MomentConstructor2 = +// [] abstract Invoke: ?inp: MomentInput * ?format: MomentFormatSpecification * ?language: string * ?strict: bool -> Moment + +// type MomentConstructor = +// U2 +""" config + |> prepend newline + |> should equal """ +[] +type IExports = + abstract DataSet: DataSetStatic + abstract DataView: DataViewStatic + abstract Graph2d: Graph2dStatic + abstract Timeline: TimelineStatic + // abstract Timeline: TimelineStaticStatic + abstract Network: NetworkStatic + +// type [] MomentConstructor1 = +// [] abstract Invoke: ?inp: MomentInput * ?format: MomentFormatSpecification * ?strict: bool -> Moment + +// type [] MomentConstructor2 = +// [] abstract Invoke: ?inp: MomentInput * ?format: MomentFormatSpecification * ?language: string * ?strict: bool -> Moment + +// type MomentConstructor = +// U2 +""" diff --git a/src/Fantomas/TokenParser.fs b/src/Fantomas/TokenParser.fs index f1077c113e..37263a37ae 100644 --- a/src/Fantomas/TokenParser.fs +++ b/src/Fantomas/TokenParser.fs @@ -262,8 +262,13 @@ let rec private getTriviaFromTokensThemSelves (allTokens: Token list) (tokens: T match tokens with | headToken::rest when (headToken.TokenInfo.TokenName = "LINE_COMMENT") -> let lineCommentTokens = + let mutable currentLineNumber = headToken.LineNumber + rest - |> List.takeWhile (fun t -> t.TokenInfo.TokenName = "LINE_COMMENT") // && t.LineNumber = headToken.LineNumber) + |> List.takeWhile (fun t -> + let take = t.TokenInfo.TokenName = "LINE_COMMENT" && t.LineNumber <= (currentLineNumber + 1) + currentLineNumber <- t.LineNumber + take) let comment = headToken