Skip to content

Commit 3a12872

Browse files
authored
Only format to alternative function application in if expression when application is multiline. Fixes #1795. (#1803)
1 parent 18be398 commit 3a12872

File tree

2 files changed

+60
-4
lines changed

2 files changed

+60
-4
lines changed

src/Fantomas.Tests/IfThenElseTests.fs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,3 +2489,55 @@ let name =
24892489
if typ.GenericParameter.IsSolveAtCompileTime then "^" else "'"
24902490
+ typ.GenericParameter.Name
24912491
"""
2492+
2493+
[<Test>]
2494+
let ``short function application in infix expression, 1795`` () =
2495+
formatSourceString
2496+
false
2497+
"""
2498+
if
2499+
FOOQueryUserToken (uint32 activeSessionId, &token) <> 0u
2500+
then
2501+
Some x
2502+
else
2503+
None
2504+
"""
2505+
config
2506+
|> prepend newline
2507+
|> should
2508+
equal
2509+
"""
2510+
if
2511+
FOOQueryUserToken(uint32 activeSessionId, &token)
2512+
<> 0u
2513+
then
2514+
Some x
2515+
else
2516+
None
2517+
"""
2518+
2519+
[<Test>]
2520+
let ``short function application in infix expression, reversed`` () =
2521+
formatSourceString
2522+
false
2523+
"""
2524+
if
2525+
0u <> FOOQueryUserToken (uint32 activeSessionId, &token)
2526+
then
2527+
Some x
2528+
else
2529+
None
2530+
"""
2531+
config
2532+
|> prepend newline
2533+
|> should
2534+
equal
2535+
"""
2536+
if
2537+
0u
2538+
<> FOOQueryUserToken(uint32 activeSessionId, &token)
2539+
then
2540+
Some x
2541+
else
2542+
None
2543+
"""

src/Fantomas/CodePrinter.fs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,19 +2109,23 @@ and genExpr astContext synExpr ctx =
21092109
| AppParenArg app ->
21102110
genAlternativeAppWithParenthesis app astContext
21112111
|> indentNlnUnindentNln
2112-
| InfixApp (s, e, AppParenArg app, e2) ->
2113-
(genAlternativeAppWithParenthesis app astContext
2112+
| InfixApp (s, e, (AppParenArg app as e1), e2) ->
2113+
(expressionFitsOnRestOfLine
2114+
(genExpr astContext e1)
2115+
(genAlternativeAppWithParenthesis app astContext)
21142116
+> ifElse (noBreakInfixOps.Contains(s)) sepSpace sepNln
21152117
+> genInfixOperator s e
21162118
+> sepSpace
21172119
+> genExpr astContext e2)
21182120
|> indentNlnUnindentNln
2119-
| InfixApp (s, e, e1, AppParenArg app) ->
2121+
| InfixApp (s, e, e1, (AppParenArg app as e2)) ->
21202122
(genExpr astContext e1
21212123
+> sepNln
21222124
+> genInfixOperator s e
21232125
+> sepSpace
2124-
+> genAlternativeAppWithParenthesis app astContext)
2126+
+> expressionFitsOnRestOfLine
2127+
(genExpr astContext e2)
2128+
(genAlternativeAppWithParenthesis app astContext))
21252129
|> indentNlnUnindentNln
21262130
// very specific fix for 1380
21272131
| SameInfixApps (Paren (lpr, AppParenArg e, rpr, pr), es) ->

0 commit comments

Comments
 (0)