Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove MultilineInfixMultilineFormatter. #1232

Merged
merged 1 commit into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 0 additions & 85 deletions docs/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,91 +476,6 @@ let WebApp =
>=> text "pong"
```

### fsharp_max_newline_infix_operator_expression_number_of_items

Control the maximum number of certain infix operators for which infix expression
can be on one line. This subset of infix operators is called the "multiline infix operators" and contains:
- `|>`
- `||>`
- `|||>`
- `>>`
- `>>=`

Default = 1.
Requires `fsharp_multiline_infix_multiline_formatter=character_width` to be
`number_of_items` to take effect. The next entry below contains more details.

`defaultConfig`

```fsharp
let fourthPower =
[ 1; 2; 3 ]
|> List.map (fun x -> x * x)
>>= (fun x -> [ x * x ])

let eigthPower =
[ 1; 2; 3 ]
|> List.map (fun x -> x * x)
>>= (fun x -> [ x * x ])
|> List.choose (fun x -> Some (x * x))
```

```fsharp
{ defaultConfig with
MaxNewlineInfixOperatorExpressionNumberOfItems = 2
MultilineInfixMultilineFormatter = MultilineFormatterType.NumberOfItems }
```

```fsharp
let fourthPower =
[ 1; 2; 3 ] |> List.map (fun x -> x * x) >>= (fun x -> [ x * x ])

let eigthPower =
[ 1; 2; 3 ]
|> List.map (fun x -> x * x)
>>= (fun x -> [ x * x ])
|> List.choose (fun x -> Some (x * x))
```

### fsharp_newline_infix_operator_expression_multiline_formatter

Split certain\* infix operator expressions into multiple lines based on the
given condition. `character_width` uses character count of the expression,
controlled by `fsharp_max_infix_operator_expression`. `number_of_items` uses the
number of same infix operators, controlled by
`fsharp_max_newline_infix_operator_expression_number_of_items`. Default =
`character_width`. Note that in either case, infix operator expressions are
still governed by `max_line_length`.

\* The operators thus split are: `|>`, `||>`, `|||>`, `>>`, `>>=`.

`defaultConfig`

```fsharp
let sq x = x * x

let secondPower =
[ 1; 2; 3; 4; 5; 6; 7; 8 ]
|> List.choose (fun aLongName -> aLongName * aLongName |> Some)

let fourthPower =
[ 1; 2; 3 ] |> List.map sq >>= (fun x -> [ sq x ])
```

`{ defaultConfig with NewlineInfixOperatorExpressionMultilineFormatter = NumberOfItems }`

```fsharp
let sq x = x * x

let secondPower =
[ 1; 2; 3; 4; 5; 6; 7; 8 ] |> List.choose (fun aLongName -> aLongName * aLongName |> Some)

let fourthPower =
[ 1; 2; 3 ]
|> List.map sq
>>= (fun x -> [ sq x ])
```

### fsharp_max_record_width

Control the maximum width for which records should be in one line. Default = 40.
Expand Down
1 change: 0 additions & 1 deletion src/Fantomas.Tests/Fantomas.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
<Compile Include="HashDirectiveTests.fs" />
<Compile Include="NumberOfItemsListOrArrayTests.fs" />
<Compile Include="NumberOfItemsRecordTests.fs" />
<Compile Include="NumberOfItemsMultilineInfixOperatorExpressionTests.fs" />
<Compile Include="SynExprNewTests.fs" />
<Compile Include="DisableElmishTests.fs" />
<Compile Include="CastTests.fs" />
Expand Down
22 changes: 0 additions & 22 deletions src/Fantomas.Tests/FormatConfigEditorConfigurationFileTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -278,28 +278,6 @@ fsharp_max_record_width = 123

config.MaxRecordWidth == 123

[<Test>]
let ``multiline infix operator expression number_of_items parsing tests`` () =
let editorConfig = """
[*.fs]
fsharp_multiline_infix_multiline_formatter = number_of_items
fsharp_max_newline_infix_operator_expression_number_of_items = 4
"""

use configFixture =
new ConfigurationFile(defaultConfig, content = editorConfig)

use fsharpFile = new FSharpFile()

let config =
EditorConfig.readConfiguration fsharpFile.FSharpFile

config.MaxNewlineInfixOperatorExpressionNumberOfItems
== 4

config.MultilineInfixMultilineFormatter
== NumberOfItems

[<Test>]
let ``infix operator expression character_width parsing test with single option`` () =
let editorConfig = """
Expand Down

This file was deleted.

21 changes: 2 additions & 19 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,7 @@ and genExpr astContext synExpr ctx =
genMultilineInfixExpr astContext e1 operatorText operatorExpr e2

| NewlineInfixApps (e, es) ->
let smallExpr =
let shortExpr =
genExpr astContext e
+> sepSpace
+> col sepSpace es (fun (s, oe, e) ->
Expand All @@ -1713,24 +1713,7 @@ and genExpr astContext synExpr ctx =
+> genExpr astContext e)

fun ctx ->
let size = getInfixOperatorExpressionSize ctx es
atCurrentColumn (isSmallExpression size smallExpr multilineExpr) ctx

| NewlineInfixApp (operatorText, operatorExpr, e1, e2) when (ctx.Config.MultilineInfixMultilineFormatter = MultilineFormatterType.NumberOfItems) ->
let expr sep =
genExpr astContext e1
+> sep
+> genInfixOperator operatorText operatorExpr
+> sepSpace
+> genExpr astContext e2

fun ctx ->
let size =
getInfixOperatorExpressionSize ctx [ operatorExpr ]

let smallExpr = expr sepSpace
let multilineExpr = expr sepNln
atCurrentColumn (isSmallExpression size smallExpr multilineExpr) ctx
atCurrentColumn (isShortExpression ctx.Config.MaxInfixOperatorExpression shortExpr multilineExpr) ctx

| SameInfixApps (e, es) ->
let shortExpr =
Expand Down
6 changes: 0 additions & 6 deletions src/Fantomas/Context.fs
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,6 @@ let internal getRecordSize ctx fields =
| MultilineFormatterType.CharacterWidth -> Size.CharacterWidth ctx.Config.MaxRecordWidth
| MultilineFormatterType.NumberOfItems -> Size.NumberOfItems(List.length fields, ctx.Config.MaxRecordNumberOfItems)

let internal getInfixOperatorExpressionSize ctx es =
match ctx.Config.MultilineInfixMultilineFormatter with
| MultilineFormatterType.CharacterWidth -> Size.CharacterWidth ctx.Config.MaxInfixOperatorExpression
| MultilineFormatterType.NumberOfItems ->
Size.NumberOfItems(List.length es, ctx.Config.MaxNewlineInfixOperatorExpressionNumberOfItems)

/// b is true, apply f1 otherwise apply f2
let internal ifElse b (f1: Context -> Context) f2 (ctx: Context) = if b then f1 ctx else f2 ctx

Expand Down
4 changes: 0 additions & 4 deletions src/Fantomas/FormatConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ type FormatConfig =
SpaceAroundDelimiter: bool
MaxIfThenElseShortWidth: Num
MaxInfixOperatorExpression: Num
MaxNewlineInfixOperatorExpressionNumberOfItems: Num
MultilineInfixMultilineFormatter: MultilineFormatterType
MaxRecordWidth: Num
MaxRecordNumberOfItems: Num
RecordMultilineFormatter: MultilineFormatterType
Expand Down Expand Up @@ -83,8 +81,6 @@ type FormatConfig =
SpaceAroundDelimiter = true
MaxIfThenElseShortWidth = 40
MaxInfixOperatorExpression = 50
MaxNewlineInfixOperatorExpressionNumberOfItems = 1
MultilineInfixMultilineFormatter = CharacterWidth
MaxRecordWidth = 40
MaxRecordNumberOfItems = 1
RecordMultilineFormatter = MultilineFormatterType.CharacterWidth
Expand Down