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

## [Unreleased]

### Changed

- Update FCS to 'Record the range of the `of` keyword in SynUnionCaseTrivia', commit 5e9647f158fe282462aba57ed83ada910a91b90e [#3502](https://github.com/fsprojects/fantomas/pull/3502)

### Fixed

- Wrong change of comment's position. The syntax tree had no range for the `of` keyword of a union case or exception, so a block comment after it, as in `exception E of (*name*) string`, was attached to the case name and printed in front of `of`. The parser now records that range, and the comment stays after the keyword. [#1959](https://github.com/fsprojects/fantomas/issues/1959)

## [8.0.5] - 2026-09-25

### Changed
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>349d6aaf1e4685a72e43b7f4a0708205e4104b4c</FCSCommitHash>
<FCSCommitHash>5e9647f158fe282462aba57ed83ada910a91b90e</FCSCommitHash>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.Core.Tests/CommentTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2391,7 +2391,7 @@ module M

module A =
type ProviderGeneratedType =
| ProviderGeneratedType (*ilOrigTyRef*) of ILTypeRef (*ilRenamedTyRef*) * ILTypeRef * ProviderGeneratedType list
| ProviderGeneratedType of (*ilOrigTyRef*) ILTypeRef (*ilRenamedTyRef*) * ILTypeRef * ProviderGeneratedType list
"""

[<Test>]
Expand Down
14 changes: 14 additions & 0 deletions src/Fantomas.Core.Tests/TypeDeclarationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,20 @@ namespace Moon
exception FooException of int
"""

[<Test>]
let ``block comment after of keyword in exception, 1959`` () =
formatSourceString
"""
exception LoadedSourceNotFoundIgnoring of (*filename*) string * range
"""
config
|> prepend newline
|> should
equal
"""
exception LoadedSourceNotFoundIgnoring of (*filename*) string * range
"""

[<Test>]
let ``type annotations`` () =
formatSourceString
Expand Down
36 changes: 36 additions & 0 deletions src/Fantomas.Core.Tests/UnionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,3 +1114,39 @@ type A =
{| A: int
LongerThanLengthDeclaration: string |}
"""

[<Test>]
let ``block comments around of keyword in union case`` () =
formatSourceString
"""
type A =
| A (* c *) of int
| B of (* c *) string * int
"""
config
|> prepend newline
|> should
equal
"""
type A =
| A (* c *) of int
| B of (* c *) string * int
"""

[<Test>]
let ``line comment after of keyword in union case`` () =
formatSourceString
"""
type A =
| A of // comment
int
"""
config
|> prepend newline
|> should
equal
"""
type A =
| A of // comment
int
"""
1 change: 1 addition & 0 deletions src/Fantomas.Core/ASTTransformer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2989,6 +2989,7 @@ let mkSynUnionCase
mkAttributes creationAide attributes,
Option.map (stn "|") trivia.BarRange,
mkSynIdent creationAide ident,
Option.map (stn "of") trivia.OfKeyword,
fields,
fullRange
)
Expand Down
6 changes: 3 additions & 3 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4762,9 +4762,9 @@ let genField (node: FieldNode) =
|> genNode node

let genUnionCase (hasVerticalBar: bool) (node: UnionCaseNode) =
let shortExpr = col sepStar node.Fields genField
let shortExpr: Context -> Context = sepSpace +> col sepStar node.Fields genField

let longExpr =
let longExpr: Context -> Context =
indentSepNlnUnindent (atCurrentColumn (col (sepStar +> sepNln) node.Fields genField))

let genBar =
Expand All @@ -4779,7 +4779,7 @@ let genUnionCase (hasVerticalBar: bool) (node: UnionCaseNode) =
sepNlnWhenWriteBeforeNewlineNotEmpty
+> genOnelinerAttributes node.Attributes
+> genSingleTextNode node.Identifier
+> onlyIf (List.isNotEmpty node.Fields) wordOf
+> optSingle (fun ofNode -> sepSpace +> genSingleTextNode ofNode) node.OfKeyword
)
+> onlyIf (List.isNotEmpty node.Fields) (expressionFitsOnRestOfLine shortExpr longExpr)
|> genNode node
Expand Down
1 change: 0 additions & 1 deletion src/Fantomas.Core/Context.fs
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,6 @@ let sepCloseT = !-")"

let wordAnd = sepSpace +> !-"and "
let wordAndFixed = !-"and"
let wordOf = sepSpace +> !-"of "

let shortExpressionWithFallback
(shortExpression: Context -> Context)
Expand Down
1 change: 0 additions & 1 deletion src/Fantomas.Core/Context.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ val sepOpenT: (Context -> Context)
val sepCloseT: (Context -> Context)
val wordAnd: (Context -> Context)
val wordAndFixed: (Context -> Context)
val wordOf: (Context -> Context)
val sepSpaceBeforeClassConstructor: ctx: Context -> Context
val sepColon: ctx: Context -> Context
val sepColonFixed: (Context -> Context)
Expand Down
3 changes: 3 additions & 0 deletions src/Fantomas.Core/SyntaxOak.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2605,6 +2605,7 @@ type UnionCaseNode
attributes: MultipleAttributeListNode option,
bar: SingleTextNode option,
identifier: SingleTextNode,
ofKeyword: SingleTextNode option,
fields: FieldNode list,
range
)
Expand All @@ -2617,13 +2618,15 @@ type UnionCaseNode
yield! noa bar
yield! noa attributes
yield identifier
yield! noa ofKeyword
yield! nodes fields
|]

member val XmlDoc = xmlDoc
member val Attributes = attributes
member val Bar = bar
member val Identifier = identifier
member val OfKeyword = ofKeyword
member val Fields = fields

/// The shared header of a type definition: `type` / `and` keyword, optional doc, attributes, name, type parameters,
Expand Down
Loading