Skip to content

Commit

Permalink
Keep extra indent for short single case DU. Fixes #1122 and #1123. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Sep 9, 2020
1 parent cd36f2c commit 8b958bf
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
56 changes: 56 additions & 0 deletions src/Fantomas.Tests/ModuleTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -544,3 +544,59 @@ namespace Foo
do ()
"""

[<Test>]
let ``keep correct indentation for let binding inside nested module, 1122`` () =
formatSourceString false """
namespace Test
module App =
type Msg = B of C
let a = "test"
""" config
|> prepend newline
|> should equal """
namespace Test
module App =
type Msg = B of C
let a = "test"
"""

[<Test>]
let ``keep correct indentation for let binding inside nested module, signature file`` () =
formatSourceString true """
namespace Test
module App =
type Msg = B of C
val a : string
""" config
|> prepend newline
|> should equal """
namespace Test
module App =
type Msg = B of C
val a: string
"""

[<Test>]
let ``nested nested module with single union DU, 1123`` () =
formatSourceString false """
module Test =
module Foo =
type t = T of bool
let foo = true
""" config
|> prepend newline
|> should equal """
module Test =
module Foo =
type t = T of bool
let foo = true
"""
4 changes: 2 additions & 2 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2997,7 +2997,7 @@ and genTypeDefn astContext (TypeDef (ats, px, ao, tds, tcs, tdr, ms, s, preferPo
HasVerticalBar = hasVerticalBar }
x)

expressionFitsOnRestOfLine (sepSpace +> expr) (indent +> sepNln +> expr) ctx
expressionFitsOnRestOfLine (indent +> sepSpace +> expr) (indent +> sepNln +> expr) ctx
| xs ->
indent
+> sepNln
Expand Down Expand Up @@ -3324,7 +3324,7 @@ and genSigTypeDefn astContext (SigTypeDef (ats, px, ao, tds, tcs, tdr, ms, s, pr
HasVerticalBar = hasVerticalBar }
x)

expressionFitsOnRestOfLine (sepSpace +> expr) (indent +> sepNln +> expr)
expressionFitsOnRestOfLine (indent +> sepSpace +> expr) (indent +> sepNln +> expr)
| xs ->
indent
+> sepNln
Expand Down

0 comments on commit 8b958bf

Please sign in to comment.