Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only format to alternative function application in if expression when application is multiline. #1803

Merged
merged 1 commit into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/Fantomas.Tests/IfThenElseTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2489,3 +2489,55 @@ let name =
if typ.GenericParameter.IsSolveAtCompileTime then "^" else "'"
+ typ.GenericParameter.Name
"""

[<Test>]
let ``short function application in infix expression, 1795`` () =
formatSourceString
false
"""
if
FOOQueryUserToken (uint32 activeSessionId, &token) <> 0u
then
Some x
else
None
"""
config
|> prepend newline
|> should
equal
"""
if
FOOQueryUserToken(uint32 activeSessionId, &token)
<> 0u
then
Some x
else
None
"""

[<Test>]
let ``short function application in infix expression, reversed`` () =
formatSourceString
false
"""
if
0u <> FOOQueryUserToken (uint32 activeSessionId, &token)
then
Some x
else
None
"""
config
|> prepend newline
|> should
equal
"""
if
0u
<> FOOQueryUserToken(uint32 activeSessionId, &token)
then
Some x
else
None
"""
12 changes: 8 additions & 4 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2109,19 +2109,23 @@ and genExpr astContext synExpr ctx =
| AppParenArg app ->
genAlternativeAppWithParenthesis app astContext
|> indentNlnUnindentNln
| InfixApp (s, e, AppParenArg app, e2) ->
(genAlternativeAppWithParenthesis app astContext
| InfixApp (s, e, (AppParenArg app as e1), e2) ->
(expressionFitsOnRestOfLine
(genExpr astContext e1)
(genAlternativeAppWithParenthesis app astContext)
+> ifElse (noBreakInfixOps.Contains(s)) sepSpace sepNln
+> genInfixOperator s e
+> sepSpace
+> genExpr astContext e2)
|> indentNlnUnindentNln
| InfixApp (s, e, e1, AppParenArg app) ->
| InfixApp (s, e, e1, (AppParenArg app as e2)) ->
(genExpr astContext e1
+> sepNln
+> genInfixOperator s e
+> sepSpace
+> genAlternativeAppWithParenthesis app astContext)
+> expressionFitsOnRestOfLine
(genExpr astContext e2)
(genAlternativeAppWithParenthesis app astContext))
|> indentNlnUnindentNln
// very specific fix for 1380
| SameInfixApps (Paren (lpr, AppParenArg e, rpr, pr), es) ->
Expand Down