Skip to content

Commit

Permalink
Don't further indent when member definition is multiline. Fixes fspro…
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed May 19, 2020
1 parent 4c8aeb8 commit 4c04360
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
23 changes: 23 additions & 0 deletions src/Fantomas.Tests/TypeDeclarationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,3 +1115,26 @@ namespace Foo
type internal Blah =
abstract Baz: unit
"""

[<Test>]
let ``keep correct indentation after multiline member definition`` () =
formatSourceString false """type SomeType() =
member SomeMember(looooooooooooooooooooooooooooooooooong1: A, looooooooooooooooooooooooooooooooooong2: A) =
printfn "a"
"a"
member SomeOtherMember () =
printfn "b"
""" ({ config with PageWidth = 80 })
|> prepend newline
|> should equal """
type SomeType() =
member SomeMember(
looooooooooooooooooooooooooooooooooong1: A,
looooooooooooooooooooooooooooooooooong2: A)
=
printfn "a"
"a"
member SomeOtherMember() = printfn "b"
"""
8 changes: 5 additions & 3 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,10 @@ and genMemberBinding astContext b =
genAttributesAndXmlDoc
+> leadingExpressionIsMultiline prefix
(fun prefixIsLong ->
ifElse prefixIsLong (sepNln +> !- "=" +> sepNln) sepEq
+> autoIndentAndNlnIfExpressionExceedsPageWidth (genExpr astContext e))
ifElse
prefixIsLong
(sepNln +> !- "=" +> sepNln +> genExpr astContext e +> unindent)
(sepEq +> autoIndentAndNlnIfExpressionExceedsPageWidth (genExpr astContext e)))

| ExplicitCtor(ats, px, ao, p, e, so) ->
let prefix =
Expand Down Expand Up @@ -1248,7 +1250,7 @@ and genExpr astContext synExpr =
// See :
// * https://github.com/fsprojects/fantomas/issues/478
// * https://github.com/fsprojects/fantomas/issues/513
firstNewlineOrComment es +> atCurrentColumn (colEx (fun (e:SynExpr) -> sepConsideringTriviaContentBefore sepSemiNln e.Range) es (genExpr astContext))
dumpAndContinue +> firstNewlineOrComment es +> atCurrentColumn (colEx (fun (e:SynExpr) -> sepConsideringTriviaContentBefore sepSemiNln e.Range) es (genExpr astContext))

| IfThenElse(e1, e2, None, mIfToThen) ->
fun (ctx:Context) ->
Expand Down

0 comments on commit 4c04360

Please sign in to comment.