Skip to content

Commit

Permalink
Fixed comments on params with attributes (#2588)
Browse files Browse the repository at this point in the history
* Fixed comments on params with attributes

* Added additional cases

* Update CHANGELOG.md
  • Loading branch information
stefan-schweiger authored Oct 19, 2022
1 parent 35f093c commit f071172
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
40 changes: 40 additions & 0 deletions src/Fantomas.Core.Tests/CommentTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2531,3 +2531,43 @@ let Anonymous =
{| FontFamily = 700 // font-weight
FontSize = 48. |} // font-weight
"""

[<Test>]
let ``comments on param with attribute, 2585`` () =
formatSourceString
false
"""
type MyType =
member _.MyMethod
(
[<MyAttribute>] inputA: string, // my comment 1
[<MyAttribute>] inputB: string // my comment 2
) =
inputA

type MyType2 =
member _.MyMethod
(
[<MyAttribute>] inputA: string // my comment 1
) =
inputA
"""
config
|> prepend newline
|> should
equal
"""
type MyType =
member _.MyMethod
(
[<MyAttribute>] inputA: string, // my comment 1
[<MyAttribute>] inputB: string // my comment 2
) =
inputA

type MyType2 =
member _.MyMethod
([<MyAttribute>] inputA: string) // my comment 1
=
inputA
"""
3 changes: 3 additions & 0 deletions src/Fantomas.Core/Trivia.fs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ 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)
| _ -> node
Expand Down

0 comments on commit f071172

Please sign in to comment.