Skip to content

Commit

Permalink
fsprojects#1238 Added function multilineRecordExprAlignBrackets
Browse files Browse the repository at this point in the history
  • Loading branch information
humberto-javier.cortes-benavides committed Jan 19, 2021
1 parent b36e5a5 commit 0edfd80
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/Fantomas.Tests/ControlStructureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -836,3 +836,35 @@ with ex ->
Infrastructure.ReportWarning ex
return None
"""

[<Test>]
let ``MultilineBlockBracketsOnSameColumn should be honored inside match block, 1238`` () =
formatSourceString
false
"""
module Foo =
let Bar () =
if x then
match foo with
| { Bar = true
Baz = _ } -> failwith "xxx"
| _ -> None
"""
{ config with
MaxLineLength = 30
MultilineBlockBracketsOnSameColumn = true}
|> prepend newline
|> should
equal
"""
module Foo =
let Bar () =
if x then
match foo with
| {
Bar = true
Baz = _
} ->
failwith "xxx"
| _ -> None
"""
15 changes: 14 additions & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4535,9 +4535,22 @@ and genPat astContext pat =
+> atCurrentColumn (col sepSemiNln xs (genPatRecordFieldName astContext))
+> sepCloseS

let multilineRecordExprAlignBrackets =
sepOpenSFixed
+> indent
+> sepNln
+> atCurrentColumn (col sepSemiNln xs (genPatRecordFieldName astContext))
+> unindent
+> sepNln
+> sepCloseSFixed
|> atCurrentColumnIndent

let multilineExpressionIfAlignBrackets =
ifAlignBrackets multilineRecordExprAlignBrackets multilineRecordExpr

fun ctx ->
let size = getRecordSize ctx xs
isSmallExpression size smallRecordExpr multilineRecordExpr ctx
isSmallExpression size smallRecordExpr multilineExpressionIfAlignBrackets ctx
| PatConst (c, r) -> genConst c r
| PatIsInst (TApp (_, [ _ ], _) as t)
| PatIsInst (TArray _ as t) ->
Expand Down

0 comments on commit 0edfd80

Please sign in to comment.