Skip to content

Commit

Permalink
POC double indentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Jan 30, 2024
1 parent de8ac50 commit e10b3a7
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 6 deletions.
30 changes: 30 additions & 0 deletions src/Fantomas.Core.Tests/ExperimentalDoubleIdentParametersTests.fs
Original file line number Diff line number Diff line change
@@ -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 }

[<Test>]
let ``initial sample`` () =
formatSourceString
"""
let sillyfuncWithParams parameterName1 ignoredParameterName2 ignoredParameterName3 =
longBody
"""
config
|> prepend newline
|> should
equal
"""
let sillyfuncWithParams
parameterName1
ignoredParameterName2
ignoredParameterName3
=
longBody
"""
1 change: 1 addition & 0 deletions src/Fantomas.Core.Tests/Fantomas.Core.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
<Compile Include="DotLambdaTests.fs" />
<Compile Include="ConstraintIntersectionTests.fs" />
<Compile Include="BeginEndTests.fs" />
<Compile Include="ExperimentalDoubleIdentParametersTests.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fantomas.Core\Fantomas.Core.fsproj" />
Expand Down
7 changes: 5 additions & 2 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
10 changes: 8 additions & 2 deletions src/Fantomas.Core/FormatConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,12 @@ type FormatConfig =

[<Category("Convention")>]
[<DisplayName("Applies the Stroustrup style to the final (two) array or list argument(s) in a function application")>]
ExperimentalElmish: bool }
ExperimentalElmish: bool

[<Category("Indentation")>]
[<DisplayName("Double indent parameters")>]
[<Description("Use double indentation for parameters.")>]
ExperimentalDoubleIndentParameters: bool }

member x.IsStroustrupStyle = x.MultilineBracketStyle = Stroustrup

Expand Down Expand Up @@ -268,4 +273,5 @@ type FormatConfig =
MultilineBracketStyle = Cramped
KeepMaxNumberOfBlankLines = 100
NewlineBeforeMultilineComputationExpression = true
ExperimentalElmish = false }
ExperimentalElmish = false
ExperimentalDoubleIndentParameters = false }
23 changes: 21 additions & 2 deletions src/Fantomas.Tests/EditorConfigurationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ fsharp_multiline_bracket_style = cramped
Assert.That(config.MultilineBracketStyle, Is.EqualTo Cramped)

[<Test>]
let fsharp_prefer_computation_expression_name_on_same_line () =
let fsharp_newline_before_multiline_computation_expression () =
let rootDir = tempName ()

let editorConfig =
Expand All @@ -526,7 +526,7 @@ fsharp_newline_before_multiline_computation_expression = false
Assert.That(config.NewlineBeforeMultilineComputationExpression, Is.False)

[<Test>]
let fsharp_stroustrup_final_list_arguments () =
let fsharp_experimental_elmish () =
let rootDir = tempName ()

let editorConfig =
Expand All @@ -543,3 +543,22 @@ fsharp_experimental_elmish = true
let config = EditorConfig.readConfiguration fsharpFile.FSharpFile

Assert.That(config.ExperimentalElmish, Is.True)

[<Test>]
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)

0 comments on commit e10b3a7

Please sign in to comment.