Skip to content

Commit

Permalink
Wrap try/with expression with atCurrentColumn. (#1747)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf authored May 22, 2021
1 parent e4b2435 commit 8611499
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
31 changes: 31 additions & 0 deletions src/Fantomas.Tests/ControlStructureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1146,3 +1146,34 @@ try
with
| exc -> ()
"""

[<Test>]
let ``try/with in infix expression should be indented, 1746`` () =
formatSourceString
false
"""
let isAbstractNonVirtualMember (m: FSharpMemberOrFunctionOrValue) =
// is an abstract member
m.IsDispatchSlot
// this member doesn't implement anything
&& (try m.ImplementedAbstractSignatures <> null && m.ImplementedAbstractSignatures.Count = 0 with _ -> true) // exceptions here trying to acces the member means we're safe
// this member is not an override
&& not m.IsOverrideOrExplicitInterfaceImplementation
"""
config
|> prepend newline
|> should
equal
"""
let isAbstractNonVirtualMember (m: FSharpMemberOrFunctionOrValue) =
// is an abstract member
m.IsDispatchSlot
// this member doesn't implement anything
&& (try
m.ImplementedAbstractSignatures <> null
&& m.ImplementedAbstractSignatures.Count = 0
with
| _ -> true) // exceptions here trying to acces the member means we're safe
// this member is not an override
&& not m.IsOverrideOrExplicitInterfaceImplementation
"""
22 changes: 12 additions & 10 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1992,16 +1992,18 @@ and genExpr astContext synExpr ctx =
atCurrentColumn (colWithNlnWhenItemIsMultilineUsingConfig items) ctx
// Could customize a bit if e is single line
| TryWith (e, cs) ->
kw TRY !- "try "
+> indent
+> sepNln
+> genExpr astContext e
+> unindent
+> kw WITH !+~ "with"
+> indentOnWith
+> sepNln
+> col sepNln cs (genClause astContext true)
+> unindentOnWith
atCurrentColumn (
kw TRY !- "try "
+> indent
+> sepNln
+> genExpr astContext e
+> unindent
+> kw WITH !+~ "with"
+> indentOnWith
+> sepNln
+> col sepNln cs (genClause astContext true)
+> unindentOnWith
)

| TryFinally (e1, e2) ->
atCurrentColumn (
Expand Down

0 comments on commit 8611499

Please sign in to comment.