diff --git a/CHANGELOG.md b/CHANGELOG.md index 91857d18b7..3303baee97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### Changed * Update FCS to 'Included get,set in range of AutoProperty', commit d508186f510681d1261291474e3f9f25485999a8 +* Update FCS to 'Add a Paren case to SynRationalConst', commit 97a5b6584b54707e3e8541fe758e1aa22132a8fe ### Added * Initial support for `SynExpr.DotLambda` [#2920](https://github.com/fsprojects/fantomas/pull/2920) (See [dotnet/fsharp#13907](https://github.com/dotnet/fsharp/pull/13907)) @@ -12,6 +13,9 @@ ### Fixed * Comment no longer attached to autoproperty. [#2948](https://github.com/fsprojects/fantomas/issues/2948) * `begin`/`end` are replaced with parens. [#2368](https://github.com/fsprojects/fantomas/issues/2368) +* Block comment in Rational between lparen and numerator is moved before lparen. [#2930](https://github.com/fsprojects/fantomas/issues/2930) +* Block comment in Rational between / and denominator is moved before /. [#2932](https://github.com/fsprojects/fantomas/issues/2932) +* Block comment in Rational between denominator and rparen is moved behind rparen. [#2933](https://github.com/fsprojects/fantomas/issues/2933) ## 6.1.3 - 2023-08-25 diff --git a/Directory.Build.props b/Directory.Build.props index 1041ed9299..ea7af583ad 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -39,7 +39,7 @@ Some common use cases include: - d508186f510681d1261291474e3f9f25485999a8 + 97a5b6584b54707e3e8541fe758e1aa22132a8fe 2.8.28 6.0.1 diff --git a/src/Fantomas.Core.Tests/SynConstTests.fs b/src/Fantomas.Core.Tests/SynConstTests.fs index ebb8e0cfc2..e81831918d 100644 --- a/src/Fantomas.Core.Tests/SynConstTests.fs +++ b/src/Fantomas.Core.Tests/SynConstTests.fs @@ -846,3 +846,48 @@ let ``block comment between ^ and exponent in SynMeasure.Power is lost, 2936`` ( """ 234 """ + +[] +let ``block comment in Rational between lparen and numerator is moved before lparen, 2930`` () = + formatSourceString + false + """ +234 +""" + config + |> prepend newline + |> should + equal + """ +234 +""" + +[] +let ``block comment in Rational between / and denominator is moved before /, 2932`` () = + formatSourceString + false + """ +234 +""" + config + |> prepend newline + |> should + equal + """ +234 +""" + +[] +let ``block comment in Rational between denominator and rparen is moved behind rparen, 2933`` () = + formatSourceString + false + """ +234 +""" + config + |> prepend newline + |> should + equal + """ +234 +""" diff --git a/src/Fantomas.Core/ASTTransformer.fs b/src/Fantomas.Core/ASTTransformer.fs index dff2b02858..9e5ea201a8 100644 --- a/src/Fantomas.Core/ASTTransformer.fs +++ b/src/Fantomas.Core/ASTTransformer.fs @@ -2024,16 +2024,39 @@ let mkSynRationalConst (creationAide: CreationAide) rc = | SynRationalConst.Integer(i, range) -> stn (creationAide.TextFromSource (fun () -> string i) range) range |> RationalConstNode.Integer - | SynRationalConst.Rational(numerator, numeratorRange, denominator, denominatorRange, range) -> + + | SynRationalConst.Paren(SynRationalConst.Rational(numerator, + numeratorRange, + divRange, + denominator, + denominatorRange, + _), + range) -> + let openingParen = + let r = + withEnd (Position.mkPos range.Start.Line (range.StartRange.StartColumn + 1)) range.StartRange + + stn "(" r + let n = stn (creationAide.TextFromSource (fun () -> string numerator) numeratorRange) numeratorRange + let div = stn "/" divRange + let d = stn (creationAide.TextFromSource (fun () -> string denominator) denominatorRange) denominatorRange - RationalConstNode.Rational(RationalNode(n, d, range)) + let closingParen = + let r = + withStart (Position.mkPos range.End.Line (range.End.Column - 1)) range.EndRange + + stn ")" r + + RationalConstNode.Rational(RationalNode(openingParen, n, div, d, closingParen, range)) + | SynRationalConst.Paren(innerRc, _) -> visit innerRc | SynRationalConst.Negate(innerRc, range) -> RationalConstNode.Negate(NegateRationalNode(stn "-" range.StartRange, visit innerRc, range)) + | SynRationalConst.Rational _ -> failwith "SynRationalConst.Rational not wrapped in SynRationalConst.Paren" visit rc diff --git a/src/Fantomas.Core/CodePrinter.fs b/src/Fantomas.Core/CodePrinter.fs index b66bb3798d..80b42ecf8f 100644 --- a/src/Fantomas.Core/CodePrinter.fs +++ b/src/Fantomas.Core/CodePrinter.fs @@ -245,11 +245,11 @@ let genRational (rat: RationalConstNode) = | RationalConstNode.Integer i -> genSingleTextNode i | RationalConstNode.Negate negate -> genSingleTextNode negate.Minus +> genRational negate.Rational | RationalConstNode.Rational rationalNode -> - genSingleTextNode (SingleTextNode("(", Fantomas.FCS.Text.Range.Zero)) + genSingleTextNode rationalNode.OpeningParen +> genSingleTextNode rationalNode.Numerator - +> genSingleTextNode (SingleTextNode("/", Fantomas.FCS.Text.Range.Zero)) + +> genSingleTextNode rationalNode.DivOp +> genSingleTextNode rationalNode.Denominator - +> genSingleTextNode (SingleTextNode(")", Fantomas.FCS.Text.Range.Zero)) + +> genSingleTextNode rationalNode.ClosingParen |> genNode rationalNode let genAttributesCore (ats: AttributeNode list) = diff --git a/src/Fantomas.Core/SyntaxOak.fs b/src/Fantomas.Core/SyntaxOak.fs index 2ce749f196..6a962202ad 100644 --- a/src/Fantomas.Core/SyntaxOak.fs +++ b/src/Fantomas.Core/SyntaxOak.fs @@ -2834,13 +2834,29 @@ type MeasureParenNode(openingParen: SingleTextNode, measure: Measure, closingPar member val Measure = measure member val ClosingParen = closingParen -type RationalNode(numerator: SingleTextNode, denominator: SingleTextNode, range: range) = +type RationalNode + ( + openingParen: SingleTextNode, + numerator: SingleTextNode, + divOp: SingleTextNode, + denominator: SingleTextNode, + closingParen: SingleTextNode, + range: range + ) = inherit NodeBase(range) - override val Children: Node array = [| yield numerator; yield denominator |] + override val Children: Node array = + [| yield openingParen + yield numerator + yield divOp + yield denominator + yield closingParen |] + member val OpeningParen = openingParen member val Numerator = numerator + member val DivOp = divOp member val Denominator = denominator + member val ClosingParen = closingParen type NegateRationalNode(minus: SingleTextNode, rationalConst: RationalConstNode, range: range) = inherit NodeBase(range)