diff --git a/src/Fantomas.Tests/CompilerDirectivesTests.fs b/src/Fantomas.Tests/CompilerDirectivesTests.fs index 25066927e8..5004856682 100644 --- a/src/Fantomas.Tests/CompilerDirectivesTests.fs +++ b/src/Fantomas.Tests/CompilerDirectivesTests.fs @@ -1765,11 +1765,13 @@ let b = " |> should equal """ -let a = " +let a = + " #if FOO " -let b = " +let b = + " #endif " """ @@ -1793,13 +1795,15 @@ let b = \"\"\" |> should equal " -let a = \"\"\" +let a = + \"\"\" \" #if FOO \" \"\"\" -let b = \"\"\" +let b = + \"\"\" #endif \"\"\" " @@ -1820,11 +1824,13 @@ let b = " |> should equal """ -let a = " +let a = + " #if FOO \"" -let b = " +let b = + " #endif " """ diff --git a/src/Fantomas.Tests/OperatorTests.fs b/src/Fantomas.Tests/OperatorTests.fs index 112080e193..7a0e67d117 100644 --- a/src/Fantomas.Tests/OperatorTests.fs +++ b/src/Fantomas.Tests/OperatorTests.fs @@ -770,7 +770,8 @@ let r = a && // && b c - Bar = \"\"\" + Bar = + \"\"\" Fooey \"\"\" |} " diff --git a/src/Fantomas.Tests/RecordTests.fs b/src/Fantomas.Tests/RecordTests.fs index c428d41d47..1b9f3a2148 100644 --- a/src/Fantomas.Tests/RecordTests.fs +++ b/src/Fantomas.Tests/RecordTests.fs @@ -408,7 +408,8 @@ let r = a && // && b c - Bar = \"\"\" + Bar = + \"\"\" Fooey \"\"\" |} " @@ -535,7 +536,8 @@ type Database = [| { Id = 0 AuthorId = 1 Title = \"What is the average wing speed of an unladen swallow?\" - Description = \"\"\" + Description = + \"\"\" Hello, yesterday I saw a flight of swallows and was wondering what their **average wing speed** is? If you know the answer please share it. @@ -545,7 +547,8 @@ If you know the answer please share it. CreatedAt = DateTime.Parse \"2017-09-14T19:57:33.103Z\" AuthorId = 0 Score = 2 - Content = \"\"\" + Content = + \"\"\" > What do you mean, an African or European Swallow? > > Monty Python’s: The Holy Grail @@ -558,7 +561,8 @@ I thought you were asking it seriously, well done. CreatedAt = DateTime.Parse \"2017-09-14T20:07:27.103Z\" AuthorId = 2 Score = 1 - Content = \"\"\" + Content = + \"\"\" Maxime, I believe you found [this blog post](http://www.saratoga.com/how-should-i-know/2013/07/what-is-the-average-air-speed-velocity-of-a-laden-swallow/). @@ -571,7 +575,8 @@ And so Robin, the conclusion of the post is: { Id = 1 AuthorId = 0 Title = \"Why did you create Fable?\" - Description = \"\"\" + Description = + \"\"\" Hello Alfonso, I wanted to know why you created Fable. Did you always plan to use F#? Or were you thinking in others languages? diff --git a/src/Fantomas.Tests/StringTests.fs b/src/Fantomas.Tests/StringTests.fs index b0993f9275..c0ddf6a71b 100644 --- a/src/Fantomas.Tests/StringTests.fs +++ b/src/Fantomas.Tests/StringTests.fs @@ -53,7 +53,8 @@ let alu = |> should equal """ -let alu = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG\ +let alu = + "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG\ GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA\ CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT\ ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA\ @@ -153,10 +154,12 @@ let ``should preserve triple-quote strings`` () = equal " type GetList() = - let switchvox_users_voicemail_getList_response = \"\"\" + let switchvox_users_voicemail_getList_response = + \"\"\" \"\"\" - let switchvox_users_voicemail_getList = \"\"\" + let switchvox_users_voicemail_getList = + \"\"\" \"\"\" member self.X = switchvox_users_voicemail_getList_response @@ -189,7 +192,8 @@ let main argv = use fun1 = R.eval ( R.parse ( - text = \"\"\" + text = + \"\"\" function(i) { x <- rnorm(1000) y <- rnorm(1000) @@ -242,7 +246,8 @@ with empty lines\"\"\" |> should equal " -let x = \"\"\"some +let x = + \"\"\"some content @@ -273,7 +278,8 @@ let ``newline in string`` () = """ [] let ``newline in string`` () = - let source = "\" + let source = + "\" \"" let triviaNodes = diff --git a/src/Fantomas.Tests/SynConstTests.fs b/src/Fantomas.Tests/SynConstTests.fs index ec6ab3af5d..766435edc3 100644 --- a/src/Fantomas.Tests/SynConstTests.fs +++ b/src/Fantomas.Tests/SynConstTests.fs @@ -241,7 +241,8 @@ let a = \\\"\\\\\\\" " [] let ``defines inside string, escaped quote`` () = - let source = \" + let source = + \" let a = \\\"\\\\\\\" #if FOO #if BAR @@ -408,9 +409,98 @@ printfn bar\"\"\" // difference is the 4 spaces on line 188 |> should equal " -let source = \"\"\"printfn foo +let source = + \"\"\"printfn foo printfn bar\"\"\" // difference is the 4 spaces on line 188 let x = 9 " + +[] +let ``multiline string in let value binding, 1556`` () = + formatSourceString + false + " +let foo = \"\"\"moo, +long +triple quotes string thing +\"\"\" +" + config + |> prepend newline + |> should + equal + " +let foo = + \"\"\"moo, +long +triple quotes string thing +\"\"\" +" + +[] +let ``multiline string in let value binding, return type`` () = + formatSourceString + false + " +let foo: string = \"\"\"moo, +long +triple quotes string thing +\"\"\" +" + config + |> prepend newline + |> should + equal + " +let foo : string = + \"\"\"moo, +long +triple quotes string thing +\"\"\" +" + +[] +let ``multiline string in let function binding, no return type`` () = + formatSourceString + false + " +let foo () = \"\"\"moo, +long +triple quotes string thing +\"\"\" +" + config + |> prepend newline + |> should + equal + " +let foo () = + \"\"\"moo, +long +triple quotes string thing +\"\"\" +" + +[] +let ``multiline string in let function binding, return type`` () = + formatSourceString + false + " +let foo () : string = \"\"\"moo, +long +triple quotes string thing +\"\"\" +" + config + |> prepend newline + |> should + equal + " +let foo () : string = + \"\"\"moo, +long +triple quotes string thing +\"\"\" +" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index eadf99ec00..d861424dc0 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -896,18 +896,14 @@ and genRecordFieldName astContext (RecordFieldName (s, eo) as node) = eo (fun e -> let expr = - match e with - | MultilineString _ -> sepSpace +> genExpr astContext e - | _ -> sepSpaceOrIndentAndNlnIfExpressionExceedsPageWidth (genExpr astContext e) + sepSpaceOrIndentAndNlnIfExpressionExceedsPageWidth (genExpr astContext e) !-s +> sepEq +> expr) |> genTriviaFor RecordField_ range and genAnonRecordFieldName astContext (AnonRecordFieldName (s, e)) = let expr = - match e with - | MultilineString _ -> sepSpace +> genExpr astContext e - | _ -> sepSpaceOrIndentAndNlnIfExpressionExceedsPageWidth (genExpr astContext e) + sepSpaceOrIndentAndNlnIfExpressionExceedsPageWidth (genExpr astContext e) !-s +> sepEq +> expr @@ -955,26 +951,18 @@ and genNamedArgumentExpr (astContext: ASTContext) operatorExpr e1 e2 = +> sepSpace +> genExpr astContext e2 - match e2 with - | MultilineString _ -> short - | _ -> - let long = - genExpr astContext e1 - +> sepSpace - +> genInfixOperator "=" operatorExpr - +> indent - +> sepNln - +> genExpr astContext e2 - +> unindent + let long = + genExpr astContext e1 + +> sepSpace + +> genInfixOperator "=" operatorExpr + +> indent + +> sepNln + +> genExpr astContext e2 + +> unindent - expressionFitsOnRestOfLine short long + expressionFitsOnRestOfLine short long and genExpr astContext synExpr ctx = - let appNlnFun e = - match e with - | MultilineString _ -> id - | _ -> autoNlnIfExpressionExceedsPageWidth - let kw tokenName f = tokN synExpr.Range tokenName f let sepOpenTFor r = tokN r LPAREN sepOpenT @@ -1665,10 +1653,6 @@ and genExpr astContext synExpr ctx = expr ctx | Paren (lpr, e, rpr, pr) -> match e with - | MultilineString _ -> - sepOpenTFor lpr - +> atCurrentColumn (genExpr astContext e +> indentIfNeeded sepNone) - +> sepCloseTFor rpr pr | LetOrUses _ -> sepOpenTFor lpr +> atCurrentColumn (genExpr astContext e) @@ -1983,7 +1967,7 @@ and genExpr astContext synExpr ctx = expressionFitsOnRestOfLine short long // Always spacing in multiple arguments - | App (e, es) -> genApp appNlnFun astContext e es + | App (e, es) -> genApp astContext e es | TypeApp (e, ts) -> genExpr astContext e +> genGenericTypeParameters astContext ts @@ -3146,7 +3130,7 @@ and genIndexers astContext node = +> genRest astContext es | _ -> sepNone -and genApp appNlnFun astContext e es ctx = +and genApp astContext e es ctx = let shortExpression = let addFirstSpace = ifElseCtx @@ -3166,7 +3150,7 @@ and genApp appNlnFun astContext e es ctx = +> sepOpenSFixed +> sepSpace +> indent - +> appNlnFun e (genExpr astContext e) + +> autoNlnIfExpressionExceedsPageWidth (genExpr astContext e) +> unindent else genExpr astContext e @@ -5168,21 +5152,7 @@ and genSynBindingValue +> genExpr astContext e +> unindent - let hasMultilineString = - match e with - | SynExpr.Const (SynConst.String (_, r), _) -> - ctx.TriviaMainNodes - |> Map.tryFindOrEmptyList SynConst_String - |> TriviaHelpers.hasMultilineString r - | SynExpr.Const (SynConst.Bytes (_, r), _) -> - ctx.TriviaMainNodes - |> Map.tryFindOrEmptyList SynConst_Bytes - |> TriviaHelpers.hasMultilineString r - | _ -> false - - if hasMultilineString then - short ctx - elif isMultiline then + if isMultiline then long ctx else isShortExpression ctx.Config.MaxValueBindingWidth short long ctx) diff --git a/src/Fantomas/SourceParser.fs b/src/Fantomas/SourceParser.fs index 3b24b4bcab..3a859d05eb 100644 --- a/src/Fantomas/SourceParser.fs +++ b/src/Fantomas/SourceParser.fs @@ -232,11 +232,6 @@ let (|String|_|) e = | SynExpr.Const (SynConst.String (s, _), _) -> Some s | _ -> None -let (|MultilineString|_|) e = - match e with - | String (s) when (String.isMultiline s) -> Some e - | _ -> None - let (|Unresolved|) (Const s as c, r) = (c, r, s) // File level patterns