Skip to content

Commit e10b3a7

Browse files
committed
POC double indentation.
1 parent de8ac50 commit e10b3a7

File tree

5 files changed

+65
-6
lines changed

5 files changed

+65
-6
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module Fantomas.Core.Tests.ExperimentalDoubleIdentParametersTests
2+
3+
open NUnit.Framework
4+
open FsUnit
5+
open Fantomas.Core.Tests.TestHelpers
6+
7+
let config =
8+
{ config with
9+
ExperimentalDoubleIndentParameters = true
10+
MaxLineLength = 10 }
11+
12+
[<Test>]
13+
let ``initial sample`` () =
14+
formatSourceString
15+
"""
16+
let sillyfuncWithParams parameterName1 ignoredParameterName2 ignoredParameterName3 =
17+
longBody
18+
"""
19+
config
20+
|> prepend newline
21+
|> should
22+
equal
23+
"""
24+
let sillyfuncWithParams
25+
parameterName1
26+
ignoredParameterName2
27+
ignoredParameterName3
28+
=
29+
longBody
30+
"""

src/Fantomas.Core.Tests/Fantomas.Core.Tests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
<Compile Include="DotLambdaTests.fs" />
133133
<Compile Include="ConstraintIntersectionTests.fs" />
134134
<Compile Include="BeginEndTests.fs" />
135+
<Compile Include="ExperimentalDoubleIdentParametersTests.fs" />
135136
</ItemGroup>
136137
<ItemGroup>
137138
<ProjectReference Include="..\Fantomas.Core\Fantomas.Core.fsproj" />

src/Fantomas.Core/CodePrinter.fs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2879,7 +2879,7 @@ let genBinding (b: BindingNode) (ctx: Context) : Context =
28792879
+> afterLetKeyword
28802880
+> sepSpace
28812881
+> genFunctionName
2882-
+> indent
2882+
+> ifElseCtx (fun ctx -> ctx.Config.ExperimentalDoubleIndentParameters) (indent +> indent) indent
28832883
+> sepNln
28842884
+> genParameters
28852885
+> onlyIf (not endsWithTupleParameter || alternativeSyntax) sepNln
@@ -2890,7 +2890,10 @@ let genBinding (b: BindingNode) (ctx: Context) : Context =
28902890
sepNln +> genSingleTextNode b.Equals
28912891
else
28922892
sepSpace +> genSingleTextNode b.Equals)
2893-
+> unindent
2893+
+> ifElseCtx
2894+
(fun ctx -> ctx.Config.ExperimentalDoubleIndentParameters)
2895+
(unindent +> unindent)
2896+
unindent
28942897
+> onlyIf hasTriviaAfterLeadingKeyword unindent)
28952898
ctx
28962899

src/Fantomas.Core/FormatConfig.fs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,12 @@ type FormatConfig =
227227

228228
[<Category("Convention")>]
229229
[<DisplayName("Applies the Stroustrup style to the final (two) array or list argument(s) in a function application")>]
230-
ExperimentalElmish: bool }
230+
ExperimentalElmish: bool
231+
232+
[<Category("Indentation")>]
233+
[<DisplayName("Double indent parameters")>]
234+
[<Description("Use double indentation for parameters.")>]
235+
ExperimentalDoubleIndentParameters: bool }
231236

232237
member x.IsStroustrupStyle = x.MultilineBracketStyle = Stroustrup
233238

@@ -268,4 +273,5 @@ type FormatConfig =
268273
MultilineBracketStyle = Cramped
269274
KeepMaxNumberOfBlankLines = 100
270275
NewlineBeforeMultilineComputationExpression = true
271-
ExperimentalElmish = false }
276+
ExperimentalElmish = false
277+
ExperimentalDoubleIndentParameters = false }

src/Fantomas.Tests/EditorConfigurationTests.fs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ fsharp_multiline_bracket_style = cramped
507507
Assert.That(config.MultilineBracketStyle, Is.EqualTo Cramped)
508508

509509
[<Test>]
510-
let fsharp_prefer_computation_expression_name_on_same_line () =
510+
let fsharp_newline_before_multiline_computation_expression () =
511511
let rootDir = tempName ()
512512

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

528528
[<Test>]
529-
let fsharp_stroustrup_final_list_arguments () =
529+
let fsharp_experimental_elmish () =
530530
let rootDir = tempName ()
531531

532532
let editorConfig =
@@ -543,3 +543,22 @@ fsharp_experimental_elmish = true
543543
let config = EditorConfig.readConfiguration fsharpFile.FSharpFile
544544

545545
Assert.That(config.ExperimentalElmish, Is.True)
546+
547+
[<Test>]
548+
let fsharp_experimental_double_indent_parameters () =
549+
let rootDir = tempName ()
550+
551+
let editorConfig =
552+
"""
553+
[*.fs]
554+
fsharp_experimental_double_indent_parameters = true
555+
"""
556+
557+
use configFixture =
558+
new ConfigurationFile(defaultConfig, rootDir, content = editorConfig)
559+
560+
use fsharpFile = new FSharpFile(rootDir)
561+
562+
let config = EditorConfig.readConfiguration fsharpFile.FSharpFile
563+
564+
Assert.That(config.ExperimentalDoubleIndentParameters, Is.True)

0 commit comments

Comments
 (0)