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

Maintain column indentation for list of functions #2446

Merged
merged 8 commits into from
Aug 24, 2022
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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## [Unreleased]

### Fixed
* List of functions misaligned and breaks (Elmish). [#2158](https://github.com/fsprojects/fantomas/issues/2158)
* Idempotency problem when Elmish Html. [#2195](https://github.com/fsprojects/fantomas/issues/2195)
* Splitting list results in code that doesn't compile. [#2201](https://github.com/fsprojects/fantomas/issues/2201)
* Idempotency problem when using a list with interpolated strings. [#2242](https://github.com/fsprojects/fantomas/issues/2242)
* Idempotency problem when using set and spread syntax. [#2392](https://github.com/fsprojects/fantomas/issues/2392)

## [5.0.0-beta-007] - 2022-08-19

### Fixed
Expand Down
19 changes: 19 additions & 0 deletions src/Fantomas.Core.Tests/ListTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2319,3 +2319,22 @@ let x: double[][] = [ [ 1.0, 2.0, 3.0 ] ]
let foo (x: double[]) (y: object[][]) : string[,] = x :> int[]
let foo<'T> (x: 'T[]) = x
"""

[<Test>]
let ``maintain indentation on function list, 2158`` () =
formatSourceString
false
"""
let fns =
Functions[Checked false
OnChange(fun _ -> s |> updateSettings)]
"""
config
|> prepend newline
|> should
equal
"""
let fns =
Functions[Checked false
OnChange(fun _ -> s |> updateSettings)]
"""
4 changes: 3 additions & 1 deletion src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1401,9 +1401,11 @@ and genExpr astContext synExpr ctx =
)

| IndexWithoutDotExpr (identifierExpr, indexExpr) ->
let genIndexExpr = genExpr astContext indexExpr

genExpr astContext identifierExpr
+> sepOpenLFixed
+> genExpr astContext indexExpr
+> expressionFitsOnRestOfLine genIndexExpr (atCurrentColumnIndent genIndexExpr)
+> sepCloseLFixed

// Result<int, string>.Ok 42
Expand Down