diff --git a/src/Fantomas.Core.Tests/ExperimentalDoubleIdentParametersTests.fs b/src/Fantomas.Core.Tests/ExperimentalDoubleIdentParametersTests.fs new file mode 100644 index 0000000000..afabb526db --- /dev/null +++ b/src/Fantomas.Core.Tests/ExperimentalDoubleIdentParametersTests.fs @@ -0,0 +1,30 @@ +module Fantomas.Core.Tests.ExperimentalDoubleIdentParametersTests + +open NUnit.Framework +open FsUnit +open Fantomas.Core.Tests.TestHelpers + +let config = + { config with + ExperimentalDoubleIndentParameters = true + MaxLineLength = 10 } + +[] +let ``initial sample`` () = + formatSourceString + """ +let sillyfuncWithParams parameterName1 ignoredParameterName2 ignoredParameterName3 = + longBody +""" + config + |> prepend newline + |> should + equal + """ +let sillyfuncWithParams + parameterName1 + ignoredParameterName2 + ignoredParameterName3 + = + longBody +""" diff --git a/src/Fantomas.Core.Tests/Fantomas.Core.Tests.fsproj b/src/Fantomas.Core.Tests/Fantomas.Core.Tests.fsproj index dcaf08cfa3..a004379070 100644 --- a/src/Fantomas.Core.Tests/Fantomas.Core.Tests.fsproj +++ b/src/Fantomas.Core.Tests/Fantomas.Core.Tests.fsproj @@ -132,6 +132,7 @@ + diff --git a/src/Fantomas.Core/CodePrinter.fs b/src/Fantomas.Core/CodePrinter.fs index 184569b140..13a8819a8e 100644 --- a/src/Fantomas.Core/CodePrinter.fs +++ b/src/Fantomas.Core/CodePrinter.fs @@ -2879,7 +2879,7 @@ let genBinding (b: BindingNode) (ctx: Context) : Context = +> afterLetKeyword +> sepSpace +> genFunctionName - +> indent + +> ifElseCtx (fun ctx -> ctx.Config.ExperimentalDoubleIndentParameters) (indent +> indent) indent +> sepNln +> genParameters +> onlyIf (not endsWithTupleParameter || alternativeSyntax) sepNln @@ -2890,7 +2890,10 @@ let genBinding (b: BindingNode) (ctx: Context) : Context = sepNln +> genSingleTextNode b.Equals else sepSpace +> genSingleTextNode b.Equals) - +> unindent + +> ifElseCtx + (fun ctx -> ctx.Config.ExperimentalDoubleIndentParameters) + (unindent +> unindent) + unindent +> onlyIf hasTriviaAfterLeadingKeyword unindent) ctx diff --git a/src/Fantomas.Core/FormatConfig.fs b/src/Fantomas.Core/FormatConfig.fs index e2abad7247..a257781b76 100644 --- a/src/Fantomas.Core/FormatConfig.fs +++ b/src/Fantomas.Core/FormatConfig.fs @@ -227,7 +227,12 @@ type FormatConfig = [] [] - ExperimentalElmish: bool } + ExperimentalElmish: bool + + [] + [] + [] + ExperimentalDoubleIndentParameters: bool } member x.IsStroustrupStyle = x.MultilineBracketStyle = Stroustrup @@ -268,4 +273,5 @@ type FormatConfig = MultilineBracketStyle = Cramped KeepMaxNumberOfBlankLines = 100 NewlineBeforeMultilineComputationExpression = true - ExperimentalElmish = false } + ExperimentalElmish = false + ExperimentalDoubleIndentParameters = false } diff --git a/src/Fantomas.Tests/EditorConfigurationTests.fs b/src/Fantomas.Tests/EditorConfigurationTests.fs index 6c00fdc2a3..dfa4c0da2f 100644 --- a/src/Fantomas.Tests/EditorConfigurationTests.fs +++ b/src/Fantomas.Tests/EditorConfigurationTests.fs @@ -507,7 +507,7 @@ fsharp_multiline_bracket_style = cramped Assert.That(config.MultilineBracketStyle, Is.EqualTo Cramped) [] -let fsharp_prefer_computation_expression_name_on_same_line () = +let fsharp_newline_before_multiline_computation_expression () = let rootDir = tempName () let editorConfig = @@ -526,7 +526,7 @@ fsharp_newline_before_multiline_computation_expression = false Assert.That(config.NewlineBeforeMultilineComputationExpression, Is.False) [] -let fsharp_stroustrup_final_list_arguments () = +let fsharp_experimental_elmish () = let rootDir = tempName () let editorConfig = @@ -543,3 +543,22 @@ fsharp_experimental_elmish = true let config = EditorConfig.readConfiguration fsharpFile.FSharpFile Assert.That(config.ExperimentalElmish, Is.True) + +[] +let fsharp_experimental_double_indent_parameters () = + let rootDir = tempName () + + let editorConfig = + """ +[*.fs] +fsharp_experimental_double_indent_parameters = true +""" + + use configFixture = + new ConfigurationFile(defaultConfig, rootDir, content = editorConfig) + + use fsharpFile = new FSharpFile(rootDir) + + let config = EditorConfig.readConfiguration fsharpFile.FSharpFile + + Assert.That(config.ExperimentalDoubleIndentParameters, Is.True)