From 6ffc17f0f73df84777b09fc931520cbb972010fb Mon Sep 17 00:00:00 2001 From: Stefan Schweiger Date: Wed, 19 Oct 2022 12:46:37 +0200 Subject: [PATCH 1/3] Fixed comments on params with attributes --- src/Fantomas.Core.Tests/CommentTests.fs | 40 +++++++++++++++++++++++++ src/Fantomas.Core/Trivia.fs | 1 + 2 files changed, 41 insertions(+) diff --git a/src/Fantomas.Core.Tests/CommentTests.fs b/src/Fantomas.Core.Tests/CommentTests.fs index 26171548dd..455c61a022 100644 --- a/src/Fantomas.Core.Tests/CommentTests.fs +++ b/src/Fantomas.Core.Tests/CommentTests.fs @@ -2531,3 +2531,43 @@ let Anonymous = {| FontFamily = 700 // font-weight FontSize = 48. |} // font-weight """ + +[] +let ``comments on param with attribute, 2585`` () = + formatSourceString + false + """ +type MyType = + member _.MyMethod + ( + [] inputA: string, // my comment 1 + [] inputB: string // my comment 2 + ) = + inputA + +type MyType2 = + member _.MyMethod + ( + [] inputA: string // my comment 1 + ) = + inputA +""" + config + |> prepend newline + |> should + equal + """ +type MyType = + member _.MyMethod + ( + [] inputA: string, // my comment 1 + [] inputB: string // my comment 2 + ) = + inputA + +type MyType2 = + member _.MyMethod + ([] inputA: string) // my comment 1 + = + inputA +""" diff --git a/src/Fantomas.Core/Trivia.fs b/src/Fantomas.Core/Trivia.fs index 647f59b5a7..52040916bd 100644 --- a/src/Fantomas.Core/Trivia.fs +++ b/src/Fantomas.Core/Trivia.fs @@ -208,6 +208,7 @@ let rec visitLastChildNode (node: TriviaNode) : TriviaNode = | SynTypeDefnSig_ | SynMemberDefn_Member -> visitLastChildNode (Array.last node.Children) | SynPat_LongIdent when not (Array.isEmpty node.Children) -> visitLastChildNode (Array.last node.Children) + | SynPat_Attrib when not (Array.isEmpty node.Children) -> visitLastChildNode (Array.last node.Children) | _ -> node let findNodeBeforeLineAndColumn (nodes: TriviaNode seq) line column = From 36ca77092e5b298c782be700932d1070f993ad91 Mon Sep 17 00:00:00 2001 From: Stefan Schweiger Date: Wed, 19 Oct 2022 12:50:32 +0200 Subject: [PATCH 2/3] Added additional cases --- src/Fantomas.Core/Trivia.fs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Fantomas.Core/Trivia.fs b/src/Fantomas.Core/Trivia.fs index 52040916bd..0494012d5d 100644 --- a/src/Fantomas.Core/Trivia.fs +++ b/src/Fantomas.Core/Trivia.fs @@ -206,9 +206,11 @@ let rec visitLastChildNode (node: TriviaNode) : TriviaNode = | SynEnumCase_ | SynTypeDefn_ | SynTypeDefnSig_ + | SynPat_Attrib + | SynPat_Named + | SynPat_Typed | SynMemberDefn_Member -> visitLastChildNode (Array.last node.Children) | SynPat_LongIdent when not (Array.isEmpty node.Children) -> visitLastChildNode (Array.last node.Children) - | SynPat_Attrib when not (Array.isEmpty node.Children) -> visitLastChildNode (Array.last node.Children) | _ -> node let findNodeBeforeLineAndColumn (nodes: TriviaNode seq) line column = From d1f7738565f35d7f4f8934052dfe5b364c08538d Mon Sep 17 00:00:00 2001 From: Stefan Schweiger Date: Wed, 19 Oct 2022 14:09:49 +0200 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61d415fd8a..f76223feb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [Unreleased] + +### Fixed +* Comments get removed for method parameter with attribute [#2585](https://github.com/fsprojects/fantomas/issues/2585) + ## [5.1.0-alpha-007] - 2022-10-14 ### Changed