Skip to content

Commit

Permalink
Capture application where function expr is IndexWithoutDotExpr. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf authored Apr 25, 2022
1 parent 52ec3e8 commit 2d32fac
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Changelog

## [Unreleased]
## [4.7.8] - 2022-04-25

### Fixed
* Breaks float range with step-size when trailing 0 is omitted. [#2171](https://github.com/fsprojects/fantomas/issues/2171)
* Fantomas inserts a space between array variable and indexer. [#2106](https://github.com/fsprojects/fantomas/issues/2106)

## [4.7.7] - 2022-04-20

Expand Down
47 changes: 47 additions & 0 deletions src/Fantomas.Tests/IndexSyntaxTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,50 @@ let a = [ 1. .. 0.1 .. 2. ]
let b = [ 1.0 .. 2. .. 10. ]
let c = [ 1.0..2.0..10.0 ]
"""

[<Test>]
let ``indexed item invocation, 2106`` () =
formatSourceString
false
"""
array1[0]()
"""
config
|> prepend newline
|> should
equal
"""
array1[0]()
"""

[<Test>]
let ``nested indexed item`` () =
formatSourceString
false
"""
let x = array1[0][0]
let y = callData["key"]["subKey"]
"""
config
|> prepend newline
|> should
equal
"""
let x = array1[0][0]
let y = callData["key"]["subKey"]
"""

[<Test>]
let ``triple nested indexed item`` () =
formatSourceString
false
"""
let meh = myList[0][1][2]
"""
config
|> prepend newline
|> should
equal
"""
let meh = myList[0][1][2]
"""
7 changes: 7 additions & 0 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2229,6 +2229,13 @@ and genExpr astContext synExpr ctx =

expressionFitsOnRestOfLine short long

| NestedIndexWithoutDotExpr (identifierExpr, indexExpr, argExpr) ->
genExpr astContext identifierExpr
+> sepOpenLFixed
+> genExpr astContext indexExpr
+> sepCloseLFixed
+> genExpr astContext argExpr

// Always spacing in multiple arguments
| App (e, es) -> genApp astContext e es
| TypeApp (e, lt, ts, gt) ->
Expand Down
6 changes: 5 additions & 1 deletion src/Fantomas/SourceParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,9 @@ let rec (|UppercaseSynType|LowercaseSynType|) (synType: SynType) =
| SynType.App (st, _, _, _, _, _, _) -> (|UppercaseSynType|LowercaseSynType|) st
| _ -> failwithf "cannot determine if synType %A is uppercase or lowercase" synType

let (|IndexWithoutDotExpr|ElmishReactWithoutChildren|ElmishReactWithChildren|NonAppExpr|) e =
let rec (|IndexWithoutDotExpr|NestedIndexWithoutDotExpr|ElmishReactWithoutChildren|ElmishReactWithChildren|NonAppExpr|)
e
=
match e with
| SynExpr.App (ExprAtomicFlag.Atomic, false, identifierExpr, SynExpr.ArrayOrListComputed (false, indexExpr, _), _) ->
IndexWithoutDotExpr(identifierExpr, indexExpr)
Expand All @@ -1763,6 +1765,8 @@ let (|IndexWithoutDotExpr|ElmishReactWithoutChildren|ElmishReactWithChildren|Non
(SynExpr.ArrayOrListComputed (isArray = false; expr = indexExpr) as argExpr),
_) when (RangeHelpers.isAdjacentTo identifierExpr.Range argExpr.Range) ->
IndexWithoutDotExpr(identifierExpr, indexExpr)
| SynExpr.App (ExprAtomicFlag.NonAtomic, false, IndexWithoutDotExpr (identifier, indexExpr), argExpr, _) ->
NestedIndexWithoutDotExpr(identifier, indexExpr, argExpr)
| SynExpr.App (_, false, OptVar (ident, _, _), ArrayOrList (sr, isArray, children, er, _), _) ->
ElmishReactWithoutChildren(ident, sr, isArray, children, er)
| SynExpr.App (_,
Expand Down

0 comments on commit 2d32fac

Please sign in to comment.