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

genNode for SimplePatNode. #2697

Merged
merged 2 commits into from
Jan 10, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Stroustrup style breaks on nested records. [#2587](https://github.com/fsprojects/fantomas/issues/2587)
* Unit is lost inside dot get chain. [#2683](https://github.com/fsprojects/fantomas/issues/2683)
* Piped multiline application is indented too far. [#2682](https://github.com/fsprojects/fantomas/issues/2682)
* Comment not assigned to first parameter in constructor. [#2692](https://github.com/fsprojects/fantomas/issues/2692)

## [5.2.0-beta-001] - 2023-01-02

Expand Down
33 changes: 33 additions & 0 deletions src/Fantomas.Core.Tests/TypeDeclarationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3422,3 +3422,36 @@ module Primitives =
#endif
BlockHeightOffset16 = BlockHeightOffset16 of uint16
"""

[<Test>]
let ``trivia before constructor parameter, 2692`` () =
formatSourceString
false
"""
type SingleAppParenLambda
(
// Expr could be a single identifier or TypeApp
functionName: Expr, parenLambda: ExprParenLambdaNode, range
) =
inherit NodeBase(range)
override this.Children = [| yield Expr.Node functionName; yield parenLambda |]
member x.FunctionName = functionName
member x.ParenLambda = parenLambda
"""
config
|> prepend newline
|> should
equal
"""
type SingleAppParenLambda
(
// Expr could be a single identifier or TypeApp
functionName: Expr,
parenLambda: ExprParenLambdaNode,
range
) =
inherit NodeBase(range)
override this.Children = [| yield Expr.Node functionName; yield parenLambda |]
member x.FunctionName = functionName
member x.ParenLambda = parenLambda
"""
10 changes: 5 additions & 5 deletions src/Fantomas.Core/ASTTransformer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2072,7 +2072,7 @@ let mkSynUnionCase
fullRange
)

let mkImplicitCtor creationAide vis (attrs: SynAttributeList list) pats (self: Ident option) (xmlDoc: PreXmlDoc) m =
let mkImplicitCtor creationAide vis (attrs: SynAttributeList list) pats (self: Ident option) (xmlDoc: PreXmlDoc) =
let openNode, closeNode =
match pats with
| SynSimplePats.SimplePats(range = StartEndRange 1 (mOpen, _, mClose))
Expand All @@ -2095,7 +2095,7 @@ let mkImplicitCtor creationAide vis (attrs: SynAttributeList list) pats (self: I
m
)
)
| SynSimplePat.Typed(SynSimplePat.Id(ident = ident; isOptional = isOptional), t, _) ->
| SynSimplePat.Typed(SynSimplePat.Id(ident = ident; isOptional = isOptional), t, m) ->
Some(
SimplePatNode(
mkAttributes creationAide [],
Expand All @@ -2105,7 +2105,7 @@ let mkImplicitCtor creationAide vis (attrs: SynAttributeList list) pats (self: I
m
)
)
| SynSimplePat.Id(ident = ident; isOptional = isOptional) ->
| SynSimplePat.Id(ident = ident; isOptional = isOptional; range = m) ->
Some(SimplePatNode(mkAttributes creationAide [], isOptional, mkIdent ident, None, m))
| _ -> None)

Expand Down Expand Up @@ -2152,8 +2152,8 @@ let mkTypeDefn

let implicitConstructorNode =
match implicitConstructor with
| Some(SynMemberDefn.ImplicitCtor(vis, attrs, pats, self, xmlDoc, m)) ->
mkImplicitCtor creationAide vis attrs pats self xmlDoc m |> Some
| Some(SynMemberDefn.ImplicitCtor(vis, attrs, pats, self, xmlDoc, _)) ->
mkImplicitCtor creationAide vis attrs pats self xmlDoc |> Some
| _ -> None

let m =
Expand Down
1 change: 1 addition & 0 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3136,6 +3136,7 @@ let genImplicitConstructor (node: ImplicitConstructorNode) =
+> onlyIf node.IsOptional (!- "?")
+> genSingleTextNode node.Identifier
+> optSingle (fun t -> sepColon +> autoIndentAndNlnIfExpressionExceedsPageWidth (genType t)) node.Type
|> genNode node

let shortPats = col sepComma node.Parameters genSimplePat

Expand Down