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
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Some common use cases include:

<!-- Versions -->
<PropertyGroup>
<FCSCommitHash>924a64e8e40c840f05fbe7113796f267dd603282</FCSCommitHash>
<FCSCommitHash>ec1f2e206445dacd88e17fbfed42c0688cb6216d</FCSCommitHash>
<StreamJsonRpcVersion>2.8.28</StreamJsonRpcVersion>
<FSharpCoreVersion>6.0.1</FSharpCoreVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Fantomas.Core.Tests.MultilineBlockBracketsOnSameColumnArrayOrListTests
module Fantomas.Core.Tests.AlignedMultilineBracketStyleArrayOrListTests

open NUnit.Framework
open FsUnit
Expand Down
25 changes: 25 additions & 0 deletions src/Fantomas.Core.Tests/AlignedMultilineBracketStyleTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1545,3 +1545,28 @@ let v = {
Lackeys = [ "Zippy" ; "George" ; "Bungle" ]
}
"""

[<Test>]
let ``anonymous struct record with trivia`` () =
formatSourceString
false
"""
struct // 1
{| // 2
// 3
X = 4
// 5
|} // 6
"""
config
|> prepend newline
|> should
equal
"""
struct // 1
{| // 2
// 3
X = 4
// 5
|} // 6
"""
8 changes: 4 additions & 4 deletions src/Fantomas.Core.Tests/CrampedMultilineBracketStyleTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1721,8 +1721,8 @@ let ``record with comments above field, indent 2`` () =
equal
"""
{ Foo =
// bar
someValue }
// bar
someValue }
"""

[<Test>]
Expand Down Expand Up @@ -1778,8 +1778,8 @@ let ``anonymous record with multiline field, indent 2`` () =
equal
"""
{| Foo =
// meh
someValue |}
// meh
someValue |}
"""

[<Test>]
Expand Down
3 changes: 2 additions & 1 deletion src/Fantomas.Core.Tests/Fantomas.Core.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<Compile Include="SpaceBeforeClassConstructorTests.fs" />
<Compile Include="SpaceBeforeMemberTests.fs" />
<Compile Include="AlignedMultilineBracketStyleTests.fs" />
<Compile Include="MultilineBlockBracketsOnSameColumnArrayOrListTests.fs" />
<Compile Include="AlignedMultilineBracketStyleArrayOrListTests.fs" />
<Compile Include="NewlineBetweenTypeDefinitionAndMembersTests.fs" />
<Compile Include="MaxValueBindingWidthTests.fs" />
<Compile Include="MaxFunctionBindingWidthTests.fs" />
Expand Down Expand Up @@ -108,6 +108,7 @@
<Compile Include="Stroustrup\ElmishTests.fs" />
<Compile Include="Stroustrup\FunctionApplicationSingleListTests.fs" />
<Compile Include="Stroustrup\FunctionApplicationDualListTests.fs" />
<Compile Include="Stroustrup\SynExprAnonRecdStructTests.fs" />
<Compile Include="IdentTests.fs" />
<Compile Include="RecordDeclarationsWithXMLDocTests.fs" />
<Compile Include="MaxIfThenShortWidthTests.fs" />
Expand Down
4 changes: 2 additions & 2 deletions src/Fantomas.Core.Tests/NumberOfItemsRecordTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,8 @@ let ``indent update anonymous record fields far enough`` () =
"""
let expected =
{| ThisIsAThing.Empty with
TheNewValue = 1
ThatValue = 2 |}
TheNewValue = 1
ThatValue = 2 |}
"""

[<Test>]
Expand Down
35 changes: 35 additions & 0 deletions src/Fantomas.Core.Tests/Stroustrup/SynExprAnonRecdStructTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Fantomas.Core.Tests.Stroustrup.SynExprAnonRecdStructTests

open NUnit.Framework
open FsUnit
open Fantomas.Core.Tests.TestHelper
open Fantomas.Core

let config =
{ config with
MultilineBracketStyle = Stroustrup }

[<Test>]
let ``anonymous struct record with trivia`` () =
formatSourceString
false
"""
struct // 1
{| // 2
// 3
X = 4
// 5
|} // 6
"""
config
|> prepend newline
|> should
equal
"""
struct // 1
{| // 2
// 3
X = 4
// 5
|} // 6
"""
25 changes: 25 additions & 0 deletions src/Fantomas.Core.Tests/StructTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,28 @@ type NameStruct() =
struct
end
"""

[<Test>]
let ``anonymous struct record with trivia`` () =
formatSourceString
false
"""
struct // 1
{| // 2
// 3
X = 4
// 5
|} // 6
"""
config
|> prepend newline
|> should
equal
"""
struct // 1
{| // 2
// 3
X = 4
// 5
|} // 6
"""
33 changes: 29 additions & 4 deletions src/Fantomas.Core/ASTTransformer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,11 @@ let mkExpr (creationAide: CreationAide) (e: SynExpr) : Expr =
| None, None ->
ExprRecordNode(stn "{" mOpen, None, fieldNodes, stn "}" mClose, exprRange)
|> Expr.Record
| SynExpr.AnonRecd(isStruct, copyInfo, recordFields, StartEndRange 2 (mOpen, _, mClose)) ->
| SynExpr.AnonRecd(true,
copyInfo,
recordFields,
(StartRange 6 (mStruct, _) & EndRange 2 (mClose, _)),
{ OpeningBraceRange = mOpen }) ->
let fields =
recordFields
|> List.choose (function
Expand All @@ -988,15 +992,36 @@ let mkExpr (creationAide: CreationAide) (e: SynExpr) : Expr =
Some(RecordFieldNode(longIdent, stn "=" mEq, mkExpr creationAide e, m))
| _ -> None)

ExprAnonRecordNode(
isStruct,
ExprAnonStructRecordNode(
stn "struct" mStruct,
stn "{|" mOpen,
Option.map (fst >> mkExpr creationAide) copyInfo,
fields,
stn "|}" mClose,
exprRange
)
|> Expr.AnonRecord
|> Expr.AnonStructRecord
| SynExpr.AnonRecd(false, copyInfo, recordFields, EndRange 2 (mClose, _), { OpeningBraceRange = mOpen }) ->
let fields =
recordFields
|> List.choose (function
| ident, Some mEq, e ->
let m = unionRanges ident.idRange e.Range

let longIdent =
IdentListNode([ IdentifierOrDot.Ident(mkIdent ident) ], ident.idRange)

Some(RecordFieldNode(longIdent, stn "=" mEq, mkExpr creationAide e, m))
| _ -> None)

ExprRecordNode(
stn "{|" mOpen,
Option.map (fst >> mkExpr creationAide) copyInfo,
fields,
stn "|}" mClose,
exprRange
)
|> Expr.Record
| SynExpr.ObjExpr(t, eio, withKeyword, bd, members, ims, StartRange 3 (mNew, _), StartEndRange 1 (mOpen, _, mClose)) ->
let interfaceNodes =
ims
Expand Down
Loading