Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed comments on params with attributes #2588

Merged
merged 3 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nitpick but all the other entries have . at end of the sentence before the [#.
No need to update it, just something I should add to the documentation.


## [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