Skip to content

Commit

Permalink
Add active pattern for empty computation expression (#3141)
Browse files Browse the repository at this point in the history
* Add active pattern for empty computation expression

* Comment out lex.fsi

* Add changelog entry
  • Loading branch information
nojaf authored Dec 12, 2024
1 parent 3009288 commit 5d7a379
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
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

0 comments on commit 5d7a379

Please sign in to comment.