@@ -389,6 +389,18 @@ let (|InfixApp|_|) synExpr =
389
389
argExpr = e2) -> Some( e1, stn operator operatorIdent.idRange, e2)
390
390
| _ -> None
391
391
392
+ let (| IndexWithoutDot | _ |) expr =
393
+ match expr with
394
+ | SynExpr.App( ExprAtomicFlag.Atomic, false , identifierExpr, SynExpr.ArrayOrListComputed( false , indexExpr, _), _) ->
395
+ Some( identifierExpr, indexExpr)
396
+ | SynExpr.App( ExprAtomicFlag.NonAtomic,
397
+ false ,
398
+ identifierExpr,
399
+ ( SynExpr.ArrayOrListComputed( isArray = false ; expr = indexExpr) as argExpr),
400
+ _) when ( RangeHelpers.isAdjacentTo identifierExpr.Range argExpr.Range) ->
401
+ Some( identifierExpr, indexExpr)
402
+ | _ -> None
403
+
392
404
let (| MultipleConsInfixApps | _ |) expr =
393
405
let rec visit expr ( headAndLastOperator : ( SynExpr * SingleTextNode ) option ) ( xs : Queue < SingleTextNode * SynExpr >) =
394
406
match expr with
@@ -636,8 +648,7 @@ let mkLinksFromFunctionName (mkLinkFromExpr: SynExpr -> LinkExpr) (functionName:
636
648
m
637
649
)
638
650
639
- [ yield ! List.take ( leftLinks.Length - 1 ) leftLinks
640
- yield mkLinkFromExpr typeAppExpr ]
651
+ [ yield ! List.cutOffLast leftLinks; yield mkLinkFromExpr typeAppExpr ]
641
652
642
653
| SynExpr.LongIdent( longDotId = sli) ->
643
654
match sli.IdentsWithTrivia with
@@ -647,7 +658,7 @@ let mkLinksFromFunctionName (mkLinkFromExpr: SynExpr -> LinkExpr) (functionName:
647
658
let leftLinks = mkLinksFromSynLongIdent sli
648
659
let lastSynIdent = List.last synIdents
649
660
650
- [ yield ! List.take ( leftLinks.Length - 1 ) leftLinks
661
+ [ yield ! List.cutOffLast leftLinks
651
662
yield ( mkLongIdentExprFromSynIdent lastSynIdent |> mkLinkFromExpr) ]
652
663
| e -> [ mkLinkFromExpr e ]
653
664
@@ -685,7 +696,7 @@ let (|ChainExpr|_|) (e: SynExpr) : LinkExpr list option =
685
696
| _ -> []
686
697
| _ -> []
687
698
688
- let leftLinks = List.take ( leftLinks.Length - 1 ) leftLinks
699
+ let leftLinks = List.cutOffLast leftLinks
689
700
690
701
continuation [ yield ! leftLinks; yield ! lastLink ])
691
702
@@ -712,15 +723,53 @@ let (|ChainExpr|_|) (e: SynExpr) : LinkExpr list option =
712
723
|> LinkExpr.Identifier ]
713
724
| _ -> []
714
725
715
- let leftLinks = List.take ( leftLinks.Length - 1 ) leftLinks
726
+ let leftLinks = List.cutOffLast leftLinks
716
727
continuation [ yield ! leftLinks; yield ! lastLink ])
728
+
729
+ // Transform `x().y[0]` into `x()` , `dot`, `y[0]`
730
+ | IndexWithoutDot( SynExpr.DotGet( expr, mDot, sli, _), indexExpr) ->
731
+ visit expr ( fun leftLinks ->
732
+ let middleLinks , lastExpr =
733
+ match List.tryLast sli.IdentsWithTrivia with
734
+ | None -> [], indexExpr
735
+ | Some lastMiddleLink ->
736
+ let middleLinks = mkLinksFromSynLongIdent sli |> List.cutOffLast
737
+
738
+ let indexWithDotExpr =
739
+ let identifierExpr = mkLongIdentExprFromSynIdent lastMiddleLink
740
+
741
+ // Create an adjacent range for the `[`,`]` in the index expression.
742
+ let adjacentRange =
743
+ mkRange
744
+ indexExpr.Range.FileName
745
+ ( Position.mkPos
746
+ identifierExpr.Range.StartLine
747
+ ( identifierExpr.Range.StartColumn + 1 ))
748
+ ( Position.mkPos indexExpr.Range.EndLine ( indexExpr.Range.EndColumn - 1 ))
749
+
750
+ SynExpr.App(
751
+ ExprAtomicFlag.Atomic,
752
+ false ,
753
+ identifierExpr,
754
+ SynExpr.ArrayOrListComputed( false , indexExpr, adjacentRange),
755
+ unionRanges identifierExpr.Range indexExpr.Range
756
+ )
757
+
758
+ middleLinks, indexWithDotExpr
759
+
760
+ continuation
761
+ [ yield ! leftLinks
762
+ yield LinkExpr.Dot mDot
763
+ yield ! middleLinks
764
+ yield LinkExpr.Expr lastExpr ])
765
+
717
766
| SynExpr.App( isInfix = false ; funcExpr = SynExpr.DotGet _ as funcExpr; argExpr = argExpr) ->
718
767
visit funcExpr ( fun leftLinks ->
719
768
match List.tryLast leftLinks with
720
769
| Some( LinkExpr.Identifier( identifierExpr)) ->
721
770
match argExpr with
722
771
| UnitExpr mUnit ->
723
- let leftLinks = List.take ( leftLinks.Length - 1 ) leftLinks
772
+ let leftLinks = List.cutOffLast leftLinks
724
773
725
774
// Compose a function application by taking the last identifier of the SynExpr.DotGet
726
775
// and the following argument expression.
@@ -730,7 +779,7 @@ let (|ChainExpr|_|) (e: SynExpr) : LinkExpr list option =
730
779
continuation [ yield ! leftLinks; yield rightLink ]
731
780
732
781
| ParenExpr( lpr, e, rpr, pr) ->
733
- let leftLinks = List.take ( leftLinks.Length - 1 ) leftLinks
782
+ let leftLinks = List.cutOffLast leftLinks
734
783
// Example: A().B(fun b -> b)
735
784
let rightLink = LinkExpr.AppParen( identifierExpr, lpr, e, rpr, pr)
736
785
continuation [ yield ! leftLinks; yield rightLink ]
@@ -772,7 +821,7 @@ let (|ChainExpr|_|) (e: SynExpr) : LinkExpr list option =
772
821
|> LinkExpr.Expr ]
773
822
| _ -> []
774
823
775
- let leftLinks = List.take ( leftLinks.Length - 1 ) leftLinks
824
+ let leftLinks = List.cutOffLast leftLinks
776
825
continuation [ yield ! leftLinks; yield ! app ])
777
826
778
827
| SynExpr.TypeApp _ as typeApp -> mkLinksFromFunctionName LinkExpr.Identifier typeApp |> continuation
@@ -1104,14 +1153,7 @@ let mkExpr (creationAide: CreationAide) (e: SynExpr) : Expr =
1104
1153
ExprInfixAppNode( mkExpr creationAide e1, operator, mkExpr creationAide e2, exprRange)
1105
1154
|> Expr.InfixApp
1106
1155
1107
- | SynExpr.App( ExprAtomicFlag.Atomic, false , identifierExpr, SynExpr.ArrayOrListComputed( false , indexExpr, _), _) ->
1108
- ExprIndexWithoutDotNode( mkExpr creationAide identifierExpr, mkExpr creationAide indexExpr, exprRange)
1109
- |> Expr.IndexWithoutDot
1110
- | SynExpr.App( ExprAtomicFlag.NonAtomic,
1111
- false ,
1112
- identifierExpr,
1113
- ( SynExpr.ArrayOrListComputed( isArray = false ; expr = indexExpr) as argExpr),
1114
- _) when ( RangeHelpers.isAdjacentTo identifierExpr.Range argExpr.Range) ->
1156
+ | IndexWithoutDot( identifierExpr, indexExpr) ->
1115
1157
ExprIndexWithoutDotNode( mkExpr creationAide identifierExpr, mkExpr creationAide indexExpr, exprRange)
1116
1158
|> Expr.IndexWithoutDot
1117
1159
0 commit comments