Skip to content

Commit

Permalink
genNode for SimplePatNode. (#2697)
Browse files Browse the repository at this point in the history
* genNode for SimplePatNode.

* Add changelog entry
  • Loading branch information
nojaf authored Jan 10, 2023
1 parent 06c7211 commit 1af0dfe
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
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

0 comments on commit 1af0dfe

Please sign in to comment.