Skip to content

Commit

Permalink
Process function applications the same way as if the DotGet would not…
Browse files Browse the repository at this point in the history
… have a lambda. Fixes fsprojects#1804.
  • Loading branch information
nojaf committed Jul 3, 2021
1 parent abd2164 commit f08a2c3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
40 changes: 40 additions & 0 deletions src/Fantomas.Tests/DotGetTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1264,3 +1264,43 @@ m
)
.HasMaxLength
"""

[<Test>]
let ``dotget chain with a lambda and ending in multiline function application, 1804`` () =
formatSourceString
false
"""
db.Schema.Users.Query
.Where(fun x -> x.Role)
.Matches(function Role.User companyId -> companyId |_->__)
.In(
db.Schema.Companies.Query
.Where(fun x -> x.LicenceId).Equals(licenceId)
.Select(fun x -> x.Id)
)
"""
config
|> prepend newline
|> should
equal
"""
db
.Schema
.Users
.Query
.Where(fun x -> x.Role)
.Matches(
function
| Role.User companyId -> companyId
| _ -> __
)
.In(
db
.Schema
.Companies
.Query
.Where(fun x -> x.LicenceId)
.Equals(licenceId)
.Select(fun x -> x.Id)
)
"""
24 changes: 16 additions & 8 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1846,6 +1846,21 @@ and genExpr astContext synExpr ctx =

let lastEsIndex = es.Length - 1

let genApp (idx: int) ((lids, e, ts): (string * range) list * SynExpr * SynType list) : Context -> Context =
let short =
genLidsWithDots lids
+> genGenericTypeParameters astContext ts
+> genSpaceBeforeLids idx lastEsIndex lids e
+> genExpr astContext e

let long =
genLidsWithDotsAndNewlines lids
+> genGenericTypeParameters astContext ts
+> genSpaceBeforeLids idx lastEsIndex lids e
+> genMultilineFunctionApplicationArguments sepOpenTFor sepCloseTFor astContext e

expressionFitsOnRestOfLine short long

let short =
genExpr astContext e
+> genExpr astContext px
Expand All @@ -1862,14 +1877,7 @@ and genExpr astContext synExpr ctx =
genLongFunctionName (genExpr astContext px)
+> indent
+> sepNln
+> coli
sepNln
es
(fun idx (lids, e, ts) ->
genLidsWithDotsAndNewlines lids
+> genGenericTypeParameters astContext ts
+> genSpaceBeforeLids idx lastEsIndex lids e
+> genExpr astContext e)
+> coli sepNln es genApp
+> unindent

fun ctx -> isShortExpression ctx.Config.MaxDotGetExpressionWidth short long ctx
Expand Down

0 comments on commit f08a2c3

Please sign in to comment.