diff --git a/src/Fantomas.Tests/AppTests.fs b/src/Fantomas.Tests/AppTests.fs index c1a7246fa8..1c4be90995 100644 --- a/src/Fantomas.Tests/AppTests.fs +++ b/src/Fantomas.Tests/AppTests.fs @@ -68,19 +68,15 @@ let a s = |> should equal @" let a s = if s <> """" then - printfn - """"""fooo + printfn """"""fooo %s %s %s -%s"""""" - (llloooooooooooooooooooooooooo s) - s +%s"""""" (llloooooooooooooooooooooooooo s) s (llloooooooooooooooooooooooooo s) (llloooooooooooooooooooooooooo s) " - [] let ``should split parameters over multiple lines when they exceed page width``() = formatSourceString false """module Caching = diff --git a/src/Fantomas.Tests/ElmishTests.fs b/src/Fantomas.Tests/ElmishTests.fs index adf5aad935..f560188a48 100644 --- a/src/Fantomas.Tests/ElmishTests.fs +++ b/src/Fantomas.Tests/ElmishTests.fs @@ -433,9 +433,11 @@ table [ ClassName "table table-striped table-hover mb-0" ] [ tokenDetailRow "ColorClass" (str colorClass) tokenDetailRow "CharClass" (str charClass) tokenDetailRow "Tag" (ofInt tag) - tokenDetailRow "FullMatchedLength" (span [ ClassName "has-text-weight-semibold" ] [ - ofInt fullMatchedLength - ]) + tokenDetailRow + "FullMatchedLength" + (span [ ClassName "has-text-weight-semibold" ] [ + ofInt fullMatchedLength + ]) ] ] """ diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 0bc64e9786..fbe0507184 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -1322,48 +1322,17 @@ and genExpr astContext synExpr = else sepSpace ctx - // This checks if there is an application with multiple parameters which would fit in one line - // but at least one of the parameters which is not the last parameter has a line comment - // In that case we have to split the arguments over multiple lines to preserve the line comments - // Example: - // - // someFunc a b c // comment - // - // This can stay as is because the last argument has the line comment - // However: - // - // someFunc - // a - // b // comment - // c - // - // This has to be split over multiple lines to preserve the line comment - let parametersMustBeNewlinedBecauseOfTriviaContent es ctx = - es - |> List.map (fun (e:SynExpr) -> TriviaHelpers.findByRange ctx.Trivia e.Range) - |> List.mapi (fun i node -> if node.IsSome && not (i = List.length es - 1) then TriviaHelpers.``has line comment after`` node.Value else false) - |> List.contains true - - fun ctx -> - let shortExpression = - (atCurrentColumn - (genExpr astContext e - +> colPre sepSpace sepSpace es (fun e -> - ifElse (isCompExpr e) - (sepSpace - +> sepOpenSFixed - +> sepSpace + let shortExpression = + atCurrentColumn + (genExpr astContext e + +> colPre sepSpace sepSpace es (fun e -> + onlyIf (isCompExpr e) (sepSpace +> sepOpenSFixed +> sepSpace) +> indent +> appNlnFun e (indentIfNeeded +> genExpr astContext e) - +> unindent) - (indent - +> indentIfNeeded - +> sepNln - +> genExpr astContext e - +> unindent)))) + +> unindent)) - let longExpression = - (atCurrentColumn + let longExpression = + (atCurrentColumn (genExpr astContext e +> colPre sepSpace sepSpace es (fun e -> ifElse (isCompExpr e) @@ -1375,11 +1344,21 @@ and genExpr astContext synExpr = +> unindent) (indent +> indentIfNeeded + +> sepNln +> genExpr astContext e +> unindent)))) - //ifElseCtx (fun ctx -> exceedsWidth ctx.Config.PageWidth longExpression ctx || parametersMustBeNewlinedBecauseOfTriviaContent es ctx) shortExpression longExpression ctx - ifElseCtx (fun ctx -> parametersMustBeNewlinedBecauseOfTriviaContent es ctx) shortExpression (expressionFitsOnRestOfLine longExpression shortExpression) ctx + if List.exists (function + | Lambda _ + | MatchLambda _ + | Paren (Lambda (_)) + | Paren (MatchLambda (_)) + | MultilineString _ + | CompExpr _ -> true + | _ -> false) es then + shortExpression + else + expressionFitsOnRestOfLine shortExpression longExpression | TypeApp(e, ts) -> genExpr astContext e -- "<" +> col sepComma ts (genType astContext false) -- ">" | LetOrUses(bs, e) ->