Skip to content

Commit

Permalink
Reset the max line length after printing the interpolated expression. F…
Browse files Browse the repository at this point in the history
…ixes #1771. (#1772)
  • Loading branch information
nojaf committed Jun 9, 2021
1 parent 2890b4a commit a79ebea
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 11 deletions.
49 changes: 49 additions & 0 deletions src/Fantomas.Tests/AppTests.fs
Expand Up @@ -659,3 +659,52 @@ SomeOtherFunction(
arg2
) // does another thing
"""

[<Test>]
let ``string interpolation should not affect multiline function applications, 1771`` () =
formatSourceString
false
"""
let tryDataOperation =
let body =
let clauses =
[ mkSynMatchClause
(mkSynPatLongIdentSimple "Some")
(mkSynExprAppNonAtomic
(mkSynExprLongIdent $"this.{memberName}")
(mkSynExprParen (
mkSynExprTuple
[ mkSynExprIdent "state" ]
))) ]
mkSynExprMatch clauses
mkMember $"this.Try{memberName}" None [ mkSynAttribute "CustomOperation" (mkSynExprConstString $"try{memberName}") ] [ parameters ] (objectStateExpr body)
"""
{ config with
IndentSize = 2
DisableElmishSyntax = true }
|> prepend newline
|> should
equal
"""
let tryDataOperation =
let body =
let clauses =
[ mkSynMatchClause
(mkSynPatLongIdentSimple "Some")
(mkSynExprAppNonAtomic
(mkSynExprLongIdent $"this.{memberName}")
(mkSynExprParen (mkSynExprTuple [ mkSynExprIdent "state" ]))) ]
mkSynExprMatch clauses
mkMember
$"this.Try{memberName}"
None
[ mkSynAttribute "CustomOperation" (mkSynExprConstString $"try{memberName}") ]
[ parameters ]
(objectStateExpr body)
"""
24 changes: 13 additions & 11 deletions src/Fantomas/CodePrinter.fs
Expand Up @@ -2465,17 +2465,19 @@ and genExpr astContext synExpr ctx =

let genInterpolatedFillExpr expr =
fun ctx ->
genExpr
astContext
expr
{ ctx with
Config =
{ ctx.Config with
// override the max line length for the interpolated expression.
// this is to avoid scenarios where the long / multiline format of the expresion will be used
// where the construct is this short
// see unit test ``construct url with Fable``
MaxLineLength = ctx.WriterModel.Column + ctx.Config.MaxLineLength } }
let currentConfig = ctx.Config

let interpolatedConfig =
{ currentConfig with
// override the max line length for the interpolated expression.
// this is to avoid scenarios where the long / multiline format of the expresion will be used
// where the construct is this short
// see unit test ``construct url with Fable``
MaxLineLength = ctx.WriterModel.Column + ctx.Config.MaxLineLength }

genExpr astContext expr { ctx with Config = interpolatedConfig }
// Restore the existing configuration after printing the interpolated expression
|> fun ctx -> { ctx with Config = currentConfig }
|> atCurrentColumnIndent

let expr =
Expand Down

0 comments on commit a79ebea

Please sign in to comment.