Skip to content

Commit

Permalink
Update records indent from the curly brace (#1892)
Browse files Browse the repository at this point in the history
* Update records indent from the curly brace.
Fixes #1876.

* WIP anonymous records

* Indent multiline record field expressions from the opening brace.

* Restore correct indent after update record expression.

* trigger CI
  • Loading branch information
nojaf committed Jan 8, 2022
1 parent 9a1f9d7 commit e21e658
Show file tree
Hide file tree
Showing 10 changed files with 651 additions and 187 deletions.
3 changes: 1 addition & 2 deletions src/Fantomas.Tests/AppTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,7 @@ let ``classes and private implicit constructors`` () =
do self.PrintMessage()
member this.PrintMessage() =
printf \"Creating MyClass2 with Data %d\" data\"\"\"
{ config with
MaxFunctionBindingWidth = 120 }
{ config with MaxFunctionBindingWidth = 120 }
"

[<Test>]
Expand Down
47 changes: 47 additions & 0 deletions src/Fantomas.Tests/CommentTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,53 @@ let a =
B = 7 }
"""

[<Test>]
let ``comment alignment above record field`` () =
formatSourceString
false
"""
let a =
{ c = 4
// foo
// bar
B = 7 }
"""
config
|> prepend newline
|> should
equal
"""
let a =
{ c = 4
// foo
// bar
B = 7 }
"""

[<Test>]
let ``comment alignment above record field, fsharp_space_around_delimiter = false`` () =
formatSourceString
false
"""
let a =
{ c = 4
// foo
// bar
B = 7 }
"""
{ config with
SpaceAroundDelimiter = false }
|> prepend newline
|> should
equal
"""
let a =
{c = 4
// foo
// bar
B = 7}
"""

[<Test>]
let ``shouldn't break on one-line comment`` () =
formatSourceString
Expand Down
8 changes: 4 additions & 4 deletions src/Fantomas.Tests/CompilerDirectivesTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1911,7 +1911,7 @@ let config =
#if WATCH
#else
"https://fsprojects.github.io/fantomas/"
"https://fsprojects.github.io/fantomas/"
#endif
}
"""
Expand Down Expand Up @@ -1944,7 +1944,7 @@ let config =
theme_variant = Some "red"
root_url =
#if WATCH
"http://localhost:8080/"
"http://localhost:8080/"
#else
#endif
Expand Down Expand Up @@ -1979,9 +1979,9 @@ let config =
theme_variant = Some "red"
root_url =
#if WATCH
"http://localhost:8080/"
"http://localhost:8080/"
#else
"https://fsprojects.github.io/fantomas/"
"https://fsprojects.github.io/fantomas/"
#endif
}
"""
Expand Down
4 changes: 2 additions & 2 deletions src/Fantomas.Tests/LambdaTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -933,8 +933,8 @@ module Foo =
module Foo =
let bar () =
{ Foo =
blah
|> Struct.map (fun _ (a, _, _) -> filterBackings a) }
blah
|> Struct.map (fun _ (a, _, _) -> filterBackings a) }
"""

[<Test>]
Expand Down
54 changes: 27 additions & 27 deletions src/Fantomas.Tests/NumberOfItemsRecordTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ let myRecord =
Progress = "foo"
Bar = { Zeta = "bar" }
Address =
{ Street = "Bakerstreet"
ZipCode = "9000" }
{ Street = "Bakerstreet"
ZipCode = "9000" }
Number = 42 }
"""

Expand All @@ -92,9 +92,9 @@ let ``update record`` () =
"""
let myRecord =
{ myOldRecord with
Level = 2
Bar = "barry"
Progress = "fooey" }
Level = 2
Bar = "barry"
Progress = "fooey" }
"""

[<Test>]
Expand Down Expand Up @@ -220,8 +220,8 @@ let ``anonymous record with multiple field update`` () =
"""
let a =
{| foo with
Level = 7
Square = 9 |}
Level = 7
Square = 9 |}
"""

[<Test>]
Expand Down Expand Up @@ -272,12 +272,12 @@ let anonRecord =
"""
let anonRecord =
{| A =
{| A1 = "string"
A2LongerIdentifier = "foo" |}
{| A1 = "string"
A2LongerIdentifier = "foo" |}
B = {| B1 = 7 |}
C =
{ C1 = "foo"
C2LongerIdentifier = "bar" }
{ C1 = "foo"
C2LongerIdentifier = "bar" }
D = { D1 = "bar" } |}
"""

Expand Down Expand Up @@ -708,8 +708,8 @@ let ``update record with standard indent`` () =
"""
let expected =
{ ThisIsAThing.Empty with
TheNewValue = 1
ThatValue = 2 }
TheNewValue = 1
ThatValue = 2 }
"""

[<Test>]
Expand Down Expand Up @@ -797,9 +797,9 @@ let config =
theme_variant = Some "red"
root_url =
#if WATCH
"http://localhost:8080/"
"http://localhost:8080/"
#else
"https://fsprojects.github.io/fantomas/"
"https://fsprojects.github.io/fantomas/"
#endif
}
"""
Expand Down Expand Up @@ -911,9 +911,9 @@ let s =
let r' =
{ r with
a = x
b = y
z = c }
a = x
b = y
z = c }
let s' =
{ s with AReallyLongExpressionThatIsMuchLongerThan50Characters = 1 }
Expand All @@ -929,9 +929,9 @@ g s { AReallyLongExpressionThatIsMuchLongerThan50Characters = 1 }
f
r'
{ r with
a = x
b = y
z = c }
a = x
b = y
z = c }
g s' { s with AReallyLongExpressionThatIsMuchLongerThan50Characters = 1 }
"""
Expand Down Expand Up @@ -1036,9 +1036,9 @@ let s =
let r' =
{| r with
a = x
b = y
z = c |}
a = x
b = y
z = c |}
let s' =
{| s with AReallyLongExpressionThatIsMuchLongerThan50Characters = 1 |}
Expand All @@ -1054,9 +1054,9 @@ g s {| AReallyLongExpressionThatIsMuchLongerThan50Characters = 1 |}
f
r'
{| r with
a = x
b = y
z = c |}
a = x
b = y
z = c |}
g s' {| s with AReallyLongExpressionThatIsMuchLongerThan50Characters = 1 |}
"""
Expand Down
8 changes: 4 additions & 4 deletions src/Fantomas.Tests/OperatorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -766,11 +766,11 @@ Fooey
"
let r =
{| Foo =
a
&& // && b
c
a
&& // && b
c
Bar =
\"\"\"
\"\"\"
Fooey
\"\"\" |}
"
Expand Down
11 changes: 5 additions & 6 deletions src/Fantomas.Tests/PatternMatchingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,7 @@ let update msg model =
let res =
match msg with
| AMessage ->
{ model with
AFieldWithAVeryVeryVeryLooooooongName = 10 }
{ model with AFieldWithAVeryVeryVeryLooooooongName = 10 }
.RecalculateTotal()
| AnotherMessage -> model
Expand Down Expand Up @@ -833,8 +832,8 @@ let private update onSubmit msg model =
| UpdateCurrency c -> { model with Currency = c }, Cmd.none
| UpdateLocation (lat, lng) ->
{ model with
Latitude = lat
Longitude = lng },
Latitude = lat
Longitude = lng },
Cmd.none
| UpdateIsDraft d -> { model with IsDraft = d }, Cmd.none
| UpdateRemark r -> { model with Remark = r }, Cmd.none
Expand Down Expand Up @@ -982,8 +981,8 @@ let draftToken =
DraftToken.Create
kind
{ token with
LeftColumn = token.LeftColumn - 1
FullMatchedLength = token.FullMatchedLength + 1 }
LeftColumn = token.LeftColumn - 1
FullMatchedLength = token.FullMatchedLength + 1 }
| Some ({ Kind = SymbolKind.ActivePattern } as ap) when token.Tag = FSharpTokenTag.RPAREN ->
DraftToken.Create SymbolKind.Ident ap.Token
| _ ->
Expand Down
Loading

0 comments on commit e21e658

Please sign in to comment.