diff --git a/src/Fantomas.Tests/DataStructureTests.fs b/src/Fantomas.Tests/DataStructureTests.fs index af37dacd68..f57fb2754a 100644 --- a/src/Fantomas.Tests/DataStructureTests.fs +++ b/src/Fantomas.Tests/DataStructureTests.fs @@ -1376,4 +1376,22 @@ let f' includeWeekend = if includeWeekend then "Saturday" "Sunday" ] +""" + +[] +let ``NamedIndexedPropertySet`` () = + formatSourceString false """analysisKey.Headers.Item(key) <- value +""" config + |> prepend newline + |> should equal """ +analysisKey.Headers.Item(key) <- value +""" + +[] +let ``DotNamedIndexedPropertySet`` () = + formatSourceString false """(foo()).Item(key) <- value +""" config + |> prepend newline + |> should equal """ +(foo()).Item(key) <- value """ \ No newline at end of file diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 7d8ba320e5..3552decb6a 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -1153,6 +1153,10 @@ and genExpr astContext synExpr = !- (sprintf "%s <- " s) +> autoIndentNlnByFuture (genExpr astContext e) | DotIndexedGet(e, es) -> addParenIfAutoNln e (genExpr astContext) -- "." +> sepOpenLFixed +> genIndexers astContext es +> sepCloseLFixed | DotIndexedSet(e1, es, e2) -> addParenIfAutoNln e1 (genExpr astContext) -- ".[" +> genIndexers astContext es -- "] <- " +> genExpr astContext e2 + | NamedIndexedPropertySet(ident, e1, e2) -> + !- ident +> genExpr astContext e1 -- " <- " +> genExpr astContext e2 + | DotNamedIndexedPropertySet(e, ident, e1, e2) -> + genExpr astContext e -- "." -- ident +> genExpr astContext e1 -- " <- " +> genExpr astContext e2 | DotGet(e, (s,_)) -> let exprF = genExpr { astContext with IsInsideDotGet = true } addParenIfAutoNln e exprF -- (sprintf ".%s" s) diff --git a/src/Fantomas/SourceParser.fs b/src/Fantomas/SourceParser.fs index 696c89d5f8..b6761cc8e2 100644 --- a/src/Fantomas/SourceParser.fs +++ b/src/Fantomas/SourceParser.fs @@ -754,6 +754,16 @@ let (|DotIndexedSet|_|) = function Some(e1, es, e2) | _ -> None +let (|NamedIndexedPropertySet|_|) = function + | SynExpr.NamedIndexedPropertySet(LongIdentWithDots ident, e1, e2, _) -> + Some(ident, e1, e2) + | _ -> None + +let (|DotNamedIndexedPropertySet|_|) = function + | SynExpr.DotNamedIndexedPropertySet(e, LongIdentWithDots ident, e1, e2, _) -> + Some(e, ident, e1, e2) + | _ -> None + let (|DotIndexedGet|_|) = function | SynExpr.DotIndexedGet(e1, es, _, _) -> Some(e1, es)