diff --git a/src/Fantomas.Tests/LetBindingTests.fs b/src/Fantomas.Tests/LetBindingTests.fs index 95464ec776..fcb694d903 100644 --- a/src/Fantomas.Tests/LetBindingTests.fs +++ b/src/Fantomas.Tests/LetBindingTests.fs @@ -1318,9 +1318,10 @@ let ``app tuple inside dotget expression`` () = """ (st :> IProvidedCustomAttributeProvider) .GetHasTypeProviderEditorHideMethodsAttribute( - info.ProvidedType.TypeProvider.PUntaintNoFailure( - id - ) + info + .ProvidedType + .TypeProvider + .PUntaintNoFailure(id) ) """ diff --git a/src/Fantomas.Tests/LongIdentWithDotsTests.fs b/src/Fantomas.Tests/LongIdentWithDotsTests.fs index 949fe859e6..79c911d517 100644 --- a/src/Fantomas.Tests/LongIdentWithDotsTests.fs +++ b/src/Fantomas.Tests/LongIdentWithDotsTests.fs @@ -303,3 +303,49 @@ let shrinkInput input = //stdout.WriteLine("Can't shrink {0} further.", sprintf "%A" input) Seq.empty """ + +[] +let ``comment in LongIdent application, 2062`` () = + formatSourceString + false + """ +Rollbar + .RollbarLocator + .RollbarInstance + // .AsBlockingLogger(System.TimeSpan.FromSeconds 5) + .Error(package, custom) +""" + config + |> prepend newline + |> should + equal + """ +Rollbar + .RollbarLocator + .RollbarInstance + // .AsBlockingLogger(System.TimeSpan.FromSeconds 5) + .Error(package, custom) +""" + +[] +let ``comment inside LongIdentWithDots preserved, 2027`` () = + formatSourceString + false + """ +let path = + match normalizedPath with + | path -> + path // translate path to Python relative syntax + .Replace("../../../", "....") +""" + config + |> prepend newline + |> should + equal + """ +let path = + match normalizedPath with + | path -> + path // translate path to Python relative syntax + .Replace("../../../", "....") +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 398a64dfba..eb21908b6b 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -1953,6 +1953,29 @@ and genExpr astContext synExpr ctx = expressionFitsOnRestOfLine short long + // path.Replace("../../../", "....") + | AppSingleParenArg (LongIdentPiecesExpr lids as functionOrMethod, px) -> + let addSpace = + onlyIfCtx (addSpaceBeforeParensInFunCall functionOrMethod px) sepSpace + + let shortLids = + col sepDot lids (fun (s, r) -> + genTriviaFor Ident_ r !-s + +> sepNlnWhenWriteBeforeNewlineNotEmpty sepNone) + + let short = shortLids +> addSpace +> genExpr astContext px + + let long = + let args = + addSpace + +> expressionFitsOnRestOfLine + (genExpr astContext px) + (genMultilineFunctionApplicationArguments astContext px) + + ifElseCtx (futureNlnCheck shortLids) (genFunctionNameWithMultilineLids args lids) (shortLids +> args) + + expressionFitsOnRestOfLine short long + | AppSingleParenArg (e, px) -> let sepSpace (ctx: Context) = match e with @@ -2805,9 +2828,7 @@ and genLidsWithDots (lids: (string * range) list) = +> col !- "." lids (fun (s, _) -> !-s) and genLidsWithDotsAndNewlines (lids: (string * range) list) = - optSingle (fun (_, r) -> enterNodeFor Ident_ r) (List.tryHead lids) - +> !- "." - +> col (sepNln +> !- ".") lids (fun (s, _) -> !-s) + col sepNln lids (fun (s, r) -> genTriviaFor Ident_ r !- $".{s}") and genSpaceBeforeLids (currentIndex: int) @@ -2833,8 +2854,7 @@ and genSpaceBeforeLids and genFunctionNameWithMultilineLids f lids = match lids with | (s, r) :: t -> - enterNodeFor Ident_ r - +> !-s + genTriviaFor Ident_ r !-s +> indent +> sepNln +> genLidsWithDotsAndNewlines t