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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## [8.0.8] - 2026-10-09

### Changed

- Update FCS to 'Add range of the when keyword to SynMatchClauseTrivia', commit 409c7a62ea193ec060e87ccad78636feeb0883f1 [#3531](https://github.com/fsprojects/fantomas/pull/3531)

### Fixed

- Comment after 'when' on its own line is lost. The syntax tree had no range for the `when` keyword of a match clause, so a comment after it had no node on its line to attach to. The parser now records that range, and the comment stays after the keyword. [#3521](https://github.com/fsprojects/fantomas/issues/3521)

## [8.0.7] - 2026-10-05

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Some common use cases include:

<!-- Versions -->
<PropertyGroup>
<FCSCommitHash>5e9647f158fe282462aba57ed83ada910a91b90e</FCSCommitHash>
<FCSCommitHash>409c7a62ea193ec060e87ccad78636feeb0883f1</FCSCommitHash>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
match x with
| _
when // c
a -> b
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
match x with
| _ when // c
a
->
b
9 changes: 8 additions & 1 deletion src/Fantomas.Core/ASTTransformer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,17 @@ let mkSynMatchClause creationAide (SynMatchClause(p, eo, e, range, _, trivia)) :
| Some r -> r
| None -> invariantViolation range $"unable to get the arrow range from trivia in %s{nameof mkSynMatchClause}"

let whenExpr: (SingleTextNode * Expr) option =
match eo, trivia.WhenKeyword with
| None, _ -> None
| Some e, Some mWhen -> Some(stn "when" mWhen, mkExpr creationAide e)
| Some _, None ->
invariantViolation range $"unable to get the when range from trivia in %s{nameof mkSynMatchClause}"

MatchClauseNode(
Option.map (stn "|") trivia.BarRange,
mkPat creationAide p,
Option.map (mkExpr creationAide) eo,
whenExpr,
stn "->" arrowRange,
mkExpr creationAide e,
fullRange
Expand Down
9 changes: 5 additions & 4 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2052,8 +2052,9 @@ let genExpr (e: Expr) =
)
+> genPatInClause clauseNode.Pattern
+> optSingle
(fun e ->
!-" when"
(fun (whenNode, e) ->
sepSpace
+> genSingleTextNode whenNode
+> expressionFitsOnRestOfLine
(sepSpace +> genExpr e)
(fun ctx ->
Expand Down Expand Up @@ -2940,8 +2941,8 @@ let genClause (isLastItem: bool) (node: MatchClauseNode) =
sepSpace
+> leadingExpressionIsMultiline
(optSingle
(fun e ->
!-"when"
(fun (whenNode, e) ->
genSingleTextNode whenNode
+> sepSpaceOrIndentAndNlnIfExpressionExceedsPageWidth (genExpr e)
+> sepSpace
)
Expand Down
15 changes: 13 additions & 2 deletions src/Fantomas.Core/SyntaxOak.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1361,15 +1361,26 @@ type ExprLambdaNode(funNode: SingleTextNode, parameters: Pattern list, arrow: Si
/// Example: `| pat when guard -> body` — a single arm of a `match` or `try…with` expression.
/// The leading bar, guard (`when` clause), and arrow are all optional depending on context.
type MatchClauseNode
(bar: SingleTextNode option, pattern: Pattern, whenExpr: Expr option, arrow: SingleTextNode, bodyExpr: Expr, range)
(
bar: SingleTextNode option,
pattern: Pattern,
whenExpr: (SingleTextNode * Expr) option,
arrow: SingleTextNode,
bodyExpr: Expr,
range: range
)
=
inherit NodeBase(range)

override val Children: Node array =
[|
yield! noa bar
yield Pattern.Node pattern
yield! noa (Option.map Expr.Node whenExpr)
match whenExpr with
| None -> ()
| Some(whenNode, whenExpr) ->
yield whenNode
yield Expr.Node whenExpr
yield arrow
yield Expr.Node bodyExpr
|]
Expand Down
Loading