Skip to content

Commit

Permalink
Add indent and newline for multiline SynExpr of SynMemberDefn.AutoPro…
Browse files Browse the repository at this point in the history
…perty. Fix #1426. (#1431)
  • Loading branch information
nojaf committed Feb 5, 2021
1 parent 5297188 commit 8a2b9b3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
51 changes: 51 additions & 0 deletions src/Fantomas.Tests/TypeDeclarationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2412,3 +2412,54 @@ type Foo =
'a -> int -> string -> string -> bool
when 'a: comparison
"""

[<Test>]
let ``member with val keyword with multiline expression, 1426`` () =
formatSourceString
false
"""
type public Foo() =
// Here it generates valid code
static member FooBarThing1 =
new TypedThingDefinition(
"StringA",
SomeLongThing.SomeProperty,
IsMandatory = new Nullable<bool>(true),
Blablablabla = moreStuff
)
// With "member val" it generates invalid code
static member val FooBarThing2 =
new TypedThingDefinition(
"StringA",
SomeLongThing.SomeProperty,
IsMandatory = new Nullable<bool>(true),
Blablablabla = moreStuff
)
"""
config
|> prepend newline
|> should
equal
"""
type public Foo() =
// Here it generates valid code
static member FooBarThing1 =
new TypedThingDefinition(
"StringA",
SomeLongThing.SomeProperty,
IsMandatory = new Nullable<bool>(true),
Blablablabla = moreStuff
)
// With "member val" it generates invalid code
static member val FooBarThing2 =
new TypedThingDefinition(
"StringA",
SomeLongThing.SomeProperty,
IsMandatory = new Nullable<bool>(true),
Blablablabla = moreStuff
)
"""
7 changes: 4 additions & 3 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4288,9 +4288,10 @@ and genMemberDefn astContext node =
-- s
+> optPre sepColon sepNone typeOpt (genType astContext false)
+> sepEq
+> sepSpace
+> genExpr astContext e
-- genPropertyKind (not isFunctionProperty) mk
+> sepSpaceOrIndentAndNlnIfExpressionExceedsPageWidth (
genExpr astContext e
-- genPropertyKind (not isFunctionProperty) mk
)

| MDAbstractSlot (ats, px, ao, s, t, vi, ValTyparDecls (tds, _, tcs), MFMemberFlags mk) ->
let (FunType namedArgs) = (t, vi)
Expand Down

0 comments on commit 8a2b9b3

Please sign in to comment.