From 8b958bf5a167e2facfb8cee4f6a78f053bd968d7 Mon Sep 17 00:00:00 2001 From: Florian Verdonck Date: Wed, 9 Sep 2020 23:23:56 +0200 Subject: [PATCH] Keep extra indent for short single case DU. Fixes #1122 and #1123. (#1125) --- src/Fantomas.Tests/ModuleTests.fs | 56 +++++++++++++++++++++++++++++++ src/Fantomas/CodePrinter.fs | 4 +-- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/Fantomas.Tests/ModuleTests.fs b/src/Fantomas.Tests/ModuleTests.fs index dee5749f7e..307d02a78a 100644 --- a/src/Fantomas.Tests/ModuleTests.fs +++ b/src/Fantomas.Tests/ModuleTests.fs @@ -544,3 +544,59 @@ namespace Foo do () """ + +[] +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" +""" + +[] +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 +""" + +[] +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 +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index f1573f6c44..acf73b770c 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -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 @@ -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