From 4c9def862f5ca9b959eaffa43000e52ec5192137 Mon Sep 17 00:00:00 2001 From: nojaf Date: Wed, 19 May 2021 20:52:56 +0200 Subject: [PATCH] KeepIndentInBranch for value bindings. Fixes #1728. --- src/Fantomas.Tests/KeepIndentInBranchTests.fs | 47 +++++++++++++++++++ src/Fantomas/CodePrinter.fs | 4 +- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/Fantomas.Tests/KeepIndentInBranchTests.fs b/src/Fantomas.Tests/KeepIndentInBranchTests.fs index f407259cc3..bd8b9a2927 100644 --- a/src/Fantomas.Tests/KeepIndentInBranchTests.fs +++ b/src/Fantomas.Tests/KeepIndentInBranchTests.fs @@ -1540,3 +1540,50 @@ let x y = let ipv4 = string result.["ipv4"] None """ + +[] +let ``value binding, 1728`` () = + formatSourceString + false + """ +let x = + if not ( + result.HasResultsFor( + [ "label" + "ipv4" + "macAddress" + "medium" + "manufacturer" ] + ) + ) then + None + else + + let label = string result.["label"] + let ipv4 = string result.["ipv4"] + None +""" + config + |> prepend newline + |> should + equal + """ +let x = + if + not ( + result.HasResultsFor( + [ "label" + "ipv4" + "macAddress" + "medium" + "manufacturer" ] + ) + ) + then + None + else + + let label = string result.["label"] + let ipv4 = string result.["ipv4"] + None +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index f8ae319eea..b59710faca 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -5305,12 +5305,12 @@ and genSynBindingValue +> genReturnType +> (fun ctx -> genEqualsInBinding (equalsRange ctx) ctx)) (fun isMultiline ctx -> - let short = genExpr astContext e + let short = genExprKeepIndentInBranch astContext e let long = indent +> sepNln - +> genExpr astContext e + +> genExprKeepIndentInBranch astContext e +> unindent if isMultiline then