Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- End of line comments after infix operators are preserved correctly. [#2287](https://github.com/fsprojects/fantomas/issues/2287)
- Lambda closing parenthesis in chained method calls is no longer placed on its own line when `MultiLineLambdaClosingNewline` is enabled. [#2553](https://github.com/fsprojects/fantomas/issues/2553)
- Long `&` (AND) patterns now break across multiple lines to respect max line length. [#1780](https://github.com/fsprojects/fantomas/issues/1780)

## [8.0.0-alpha-002] - 2025-12-15

Expand Down
26 changes: 26 additions & 0 deletions src/Fantomas.Core.Tests/PatternMatchingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2313,3 +2313,29 @@ let value =
"111111111111111111111111111111111111111111111111111111111111111111111", "22222222222222222222222222222222222")
||> createTuple
"""

[<Test>]
let ``long and pattern respects max line length, 1780`` () =
formatSourceString
"""
let v, x =
match n with
| Voluptatem voluptatem & Praesentium praesentium & Molestiae molestiae & Repudiandae repudiandae & Exercitationem exercitationem & Assumenda assumenda ->
libero, []
| _ -> saepe, delectus
"""
config
|> prepend newline
|> should
equal
"""
let v, x =
match n with
| Voluptatem voluptatem
& Praesentium praesentium
& Molestiae molestiae
& Repudiandae repudiandae
& Exercitationem exercitationem
& Assumenda assumenda -> libero, []
| _ -> saepe, delectus
"""
12 changes: 11 additions & 1 deletion src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2618,7 +2618,17 @@ let genPat (p: Pattern) =
match p with
| Pattern.OptionalVal n -> genSingleTextNode n
| Pattern.Or node -> genPatLeftMiddleRight node
| Pattern.Ands node -> col (!-" & ") node.Patterns genPat |> genNode node
| Pattern.Ands node ->
let short = col (!-" & ") node.Patterns genPat

let long =
match node.Patterns with
| [] -> sepNone
| head :: rest ->
genPat head
+> indentSepNlnUnindent (col sepNln rest (fun p -> !-"& " +> genPat p))

expressionFitsOnRestOfLine short long |> genNode node
| Pattern.Null node
| Pattern.Wild node -> genSingleTextNode node
| Pattern.Parameter node ->
Expand Down