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 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
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`` () =
cgravill marked this conversation as resolved.
Show resolved Hide resolved
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)]
"""
15 changes: 11 additions & 4 deletions src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1401,10 +1401,17 @@ and genExpr astContext synExpr ctx =
)

| IndexWithoutDotExpr (identifierExpr, indexExpr) ->
genExpr astContext identifierExpr
+> sepOpenLFixed
+> genExpr astContext indexExpr
+> sepCloseLFixed
match indexExpr with
| Sequential _ ->
cgravill marked this conversation as resolved.
Show resolved Hide resolved
genExpr astContext identifierExpr
+> sepOpenLFixed
+> (genExpr astContext indexExpr |> atCurrentColumnIndent)
+> sepCloseLFixed
| _ ->
genExpr astContext identifierExpr
+> sepOpenLFixed
+> genExpr astContext indexExpr
+> sepCloseLFixed

// Result<int, string>.Ok 42
| App (DotGet (TypeApp (e, lt, ts, gt), sli), es) ->
Expand Down