Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep Subsequent identifier links on the same line. #2713

Merged
merged 3 commits into from
Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixed
* Trivia before open statement is not preserved. [#2704](https://github.com/fsprojects/fantomas/issues/2704)
* Type app identifier is considered as an expression. [#2705](https://github.com/fsprojects/fantomas/issues/2705)
* Subsequent identifier links in chain should be on the same line. [#2712](https://github.com/fsprojects/fantomas/issues/2712)

## [5.2.0-alpha-011] - 2023-01-12

Expand Down
49 changes: 49 additions & 0 deletions src/Fantomas.Core.Tests/ChainTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,52 @@ Map
Map.empty<_, obj>
.Add("headerAction", modifyHeader.Action.ArmValue)
"""

[<Test>]
let ``all simple links should be on the same line, 2712`` () =
formatSourceString
false
"""
type Duck() =
member this.Duck = Duck ()
member this.Goose() = Duck()

let d = Duck()

d.Duck.Duck.Duck.Goose().Duck.Goose().Duck.Duck.Goose().Duck.Duck.Duck.Goose().Duck.Duck.Duck.Duck.Goose()
"""
config
|> prepend newline
|> should
equal
"""
type Duck() =
member this.Duck = Duck()
member this.Goose() = Duck()

let d = Duck()

d.Duck.Duck.Duck
.Goose()
.Duck.Goose()
.Duck.Duck.Goose()
.Duck.Duck.Duck.Goose()
.Duck.Duck.Duck.Duck.Goose()
"""

[<Test>]
let ``very long chain with a some index expressions`` () =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dawedawe this one is a bit tricky. The whole chain does not fit within the MaxDotGetExpressionWidth boundary, but there is no application to chop it logically.

formatSourceString
false
"""
Universe.Galaxy.SolarSystem.Planet.[3].Countries.[9].People.Count
"""
{ config with
MaxDotGetExpressionWidth = 0 }
|> prepend newline
|> should
equal
"""
Universe
.Galaxy.SolarSystem.Planet.[3].Countries.[9].People.Count
"""
3 changes: 1 addition & 2 deletions src/Fantomas.Core.Tests/LambdaTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,7 @@ CloudStorageAccount.SetConfigurationSettingPublisher(fun configName configSettin
RoleEnvironment.GetConfigurationSettingValue(configName)
else
ConfigurationManager
.ConnectionStrings.[configName]
.ConnectionString
.ConnectionStrings.[configName].ConnectionString

configSettingPublisher.Invoke(connectionString)
|> ignore)
Expand Down
3 changes: 1 addition & 2 deletions src/Fantomas.Core.Tests/TypeDeclarationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -825,8 +825,7 @@ type BlobHelper(Account: CloudStorageAccount) =
RoleEnvironment.GetConfigurationSettingValue(configName)
else
ConfigurationManager
.ConnectionStrings.[configName]
.ConnectionString
.ConnectionStrings.[configName].ConnectionString

configSettingPublisher.Invoke(connectionString)
|> ignore)
Expand Down
6 changes: 4 additions & 2 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1096,8 +1096,10 @@ let genExpr (e: Expr) =

if lastLinkWasSimple && not (futureNlnCheck genDotAndLink ctx) then
// The last link was an identifier and the current link fits on the remainder of the current line.
genIndentedLinks currentIsSimple rest ((genDotAndLink +> onlyIfNot isLast sepNln) ctx)
genIndentedLinks currentIsSimple rest (genDotAndLink ctx)
else
let ctx' = onlyIfNot lastLinkWasSimple sepNlnUnlessLastEventIsNewline ctx

genIndentedLinks
currentIsSimple
rest
Expand All @@ -1106,7 +1108,7 @@ let genExpr (e: Expr) =
// Don't suffix with a newline if we are at the end of the chain,
// or if the current link is an identifier.
+> onlyIfNot (isLast || currentIsSimple) sepNln)
ctx)
ctx')
| _ -> failwith "Expected dot in chain at this point"

let genFirstLinkAndIndentOther (firstLink: ChainLink) (others: ChainLink list) =
Expand Down