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

Add active pattern for empty computation expression #3141

Merged
merged 3 commits into from
Dec 12, 2024
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 7.0.0-alpha-004 - 2024-12-12

### Fixed
* (Empty/NoEmpty)-bodied named computation expression produces inconsistent formatting. [#3140](https://github.com/fsprojects/fantomas/issues/3140)

## 7.0.0-alpha-003 - 2024-11-29

### Removed
Expand Down
14 changes: 14 additions & 0 deletions src/Fantomas.Core.Tests/ComputationExpressionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2453,3 +2453,17 @@ let zero =
async { () } // foo
|> ignore
"""

[<Test>]
let ``empty computation expression with application`` () =
formatSourceString
"""
A() {}
"""
config
|> prepend newline
|> should
equal
"""
A() { }
"""
19 changes: 19 additions & 0 deletions src/Fantomas.Core/ASTTransformer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,15 @@ let (|IndexWithoutDot|_|) expr =
Some(identifierExpr, indexExpr)
| _ -> None

let (|EmptyComputationExpr|_|) expr =
match expr with
| SynExpr.App(ExprAtomicFlag.NonAtomic,
false,
funcExpr,
SynExpr.Record(recordFields = []; range = StartEndRange 1 (mOpen, _, mClose)),
range) -> Some(funcExpr, mOpen, mClose, range)
| _ -> None

let (|MultipleConsInfixApps|_|) expr =
let rec visit expr (headAndLastOperator: (SynExpr * SingleTextNode) option) (xs: Queue<SingleTextNode * SynExpr>) =
match expr with
Expand Down Expand Up @@ -1252,6 +1261,16 @@ let mkExpr (creationAide: CreationAide) (e: SynExpr) : Expr =
ExprIndexWithoutDotNode(mkExpr creationAide identifierExpr, mkExpr creationAide indexExpr, exprRange)
|> Expr.IndexWithoutDot

| EmptyComputationExpr(expr, mOpen, mClose, m) ->
ExprNamedComputationNode(
mkExpr creationAide expr,
stn "{" mOpen,
Expr.Ident(stn "" Range.Zero),
stn "}" mClose,
m
)
|> Expr.NamedComputation

| ChainExpr links ->
let chainLinks =
links
Expand Down
6 changes: 3 additions & 3 deletions src/Fantomas.FCS/Fantomas.FCS.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@
<Compile Include="$(FsYaccOutputFolder)pplex.fs">
<Link>SyntaxTree\FsLexOutput\pplex.fs</Link>
</Compile>
<Compile Include="$(FsYaccOutputFolder)\lex.fsi">
<Link>SyntaxTree\FsLexOutput\lex.fsi</Link>
</Compile>
<!-- <Compile Include="$(FsYaccOutputFolder)\lex.fsi">-->
<!-- <Link>SyntaxTree\FsLexOutput\lex.fsi</Link>-->
<!-- </Compile>-->
<Compile Include="$(FsYaccOutputFolder)\lex.fs">
<Link>SyntaxTree\FsLexOutput\lex.fs</Link>
</Compile>
Expand Down
Loading