Skip to content

Commit

Permalink
Update FCS to 'Parser: recover on unfinished record decls (fsprojects…
Browse files Browse the repository at this point in the history
…#3006)

* Update FCS to 'Parser: recover on unfinished record decls, fix field ranges'

* Add changelog entry for FCS update.

* Fix missing trivia after mutable keyword
  • Loading branch information
nojaf committed Dec 1, 2023
1 parent cee9a9e commit a187cc5
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
### Fixed
* Process is reserved keyword. [#2996](https://github.com/fsprojects/fantomas/issues/2996)
* Always yield list items on separate lines if a conditional is present. [#2972](https://github.com/fsprojects/fantomas/issues/2972)
* Trivia after mutable keyword is missing. [#3005](https://github.com/fsprojects/fantomas/issues/3005)

### Changed
* Update FCS to 'Parser: recover on unfinished record decls, fix field ranges ', commit ee4a810ffe9e984e2ec8c55a9cb6d1c6631dd0b3 [#3006](https://github.com/fsprojects/fantomas/pull/3006)

## 6.3.0-alpha-003 - 2023-11-15

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

<!-- Versions -->
<PropertyGroup>
<FCSCommitHash>f42bdae84727fc251a6e570c2f1c47a3deffe215</FCSCommitHash>
<FCSCommitHash>ee4a810ffe9e984e2ec8c55a9cb6d1c6631dd0b3</FCSCommitHash>
<StreamJsonRpcVersion>2.8.28</StreamJsonRpcVersion>
<FSharpCoreVersion>6.0.1</FSharpCoreVersion>
</PropertyGroup>
Expand Down
24 changes: 24 additions & 0 deletions src/Fantomas.Core.Tests/TypeDeclarationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3531,3 +3531,27 @@ let typographyLabel<'msg, 'marker & #IFabLabel & #IFoo & #Bar>() = ()
"""
let typographyLabel<'msg, 'marker & #IFabLabel & #IFoo & #Bar> () = ()
"""

[<Test>]
let ``trivia after mutable keyword, 3005`` () =
formatSourceString
"""
type R =
{
F1: int
mutable // voobar
F2: int
F3: int
}
"""
config
|> prepend newline
|> should
equal
"""
type R =
{ F1: int
mutable // voobar
F2: int
F3: int }
"""
22 changes: 13 additions & 9 deletions src/Fantomas.Core/ASTTransformer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2337,22 +2337,26 @@ let mkSynLeadingKeyword (lk: SynLeadingKeyword) =

let mkSynField
(creationAide: CreationAide)
(SynField(ats, _isStatic, ido, t, isMutable, px, ao, range, { LeadingKeyword = lk }))
(SynField(ats,
_isStatic,
ido,
t,
_,
px,
ao,
range,
{ LeadingKeyword = lk
MutableKeyword = mk }))
=
let m =
match ats with
| [] -> range
| head :: _ -> unionRanges head.Range range

FieldNode(
mkXmlDoc px,
mkAttributes creationAide ats,
Option.map mkSynLeadingKeyword lk,
isMutable,
Option.map (stn "mutable") mk,
mkSynAccess ao,
Option.map mkIdent ido,
mkType creationAide t,
m
range
)

let mkSynUnionCase
Expand Down Expand Up @@ -2757,7 +2761,7 @@ let mkMemberDefn (creationAide: CreationAide) (md: SynMemberDefn) =
memberDefn = SynBinding(
attributes = ats
xmlDoc = px
valData = SynValData(Some { MemberKind = SynMemberKind.Constructor }, _, ido, _)
valData = SynValData(memberFlags = Some { MemberKind = SynMemberKind.Constructor }; thisIdOpt = ido)
headPat = SynPat.LongIdent(
longDotId = SynLongIdent(id = [ newIdent ])
argPats = SynArgPats.Pats [ SynPat.Paren _ as pat ]
Expand Down
19 changes: 11 additions & 8 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3611,17 +3611,20 @@ let genTypeInSignature (t: Type) =
| _ -> autoIndentAndNlnIfExpressionExceedsPageWidth (genType t)

let genField (node: FieldNode) =
let genAccessAndFieldContent =
genAccessOpt node.Accessibility
+> (match node.Name with
| None -> genType node.Type
| Some name ->
genSingleTextNode name
+> sepColon
+> autoIndentAndNlnTypeUnlessStroustrup genType node.Type)

genXml node.XmlDoc
+> genAttributes node.Attributes
+> optSingle (fun lk -> genMultipleTextsNode lk +> sepSpace) node.LeadingKeyword
+> onlyIf node.IsMutable (!- "mutable ")
+> genAccessOpt node.Accessibility
+> (match node.Name with
| None -> genType node.Type
| Some name ->
genSingleTextNode name
+> sepColon
+> autoIndentAndNlnTypeUnlessStroustrup genType node.Type)
+> optSingle (fun mk -> genSingleTextNode mk +> onlyIfNot mk.HasContentAfter sepSpace) node.MutableKeyword
+> ifElseCtx hasWriteBeforeNewlineContent (indentSepNlnUnindent genAccessAndFieldContent) genAccessAndFieldContent
|> genNode node

let genUnionCase (hasVerticalBar: bool) (node: UnionCaseNode) =
Expand Down
5 changes: 3 additions & 2 deletions src/Fantomas.Core/SyntaxOak.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2046,7 +2046,7 @@ type FieldNode
xmlDoc: XmlDocNode option,
attributes: MultipleAttributeListNode option,
leadingKeyword: MultipleTextsNode option,
isMutable: bool,
mutableKeyword: SingleTextNode option,
accessibility: SingleTextNode option,
name: SingleTextNode option,
t: Type,
Expand All @@ -2058,14 +2058,15 @@ type FieldNode
[| yield! noa xmlDoc
yield! noa attributes
yield! noa leadingKeyword
yield! noa mutableKeyword
yield! noa accessibility
yield! noa name
yield Type.Node t |]

member val XmlDoc = xmlDoc
member val Attributes = attributes
member val LeadingKeyword = leadingKeyword
member val IsMutable = isMutable
member val MutableKeyword = mutableKeyword
member val Accessibility = accessibility
member val Name = name
member val Type = t
Expand Down

0 comments on commit a187cc5

Please sign in to comment.