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

Support NamedIndexedPropertySet, DotNamedIndexedPropertySet. Fix #497 #514

Merged
merged 17 commits into from
Oct 16, 2019
Merged
18 changes: 18 additions & 0 deletions src/Fantomas.Tests/DataStructureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1376,4 +1376,22 @@ let f' includeWeekend =
if includeWeekend then
"Saturday"
"Sunday" ]
"""

[<Test>]
let ``NamedIndexedPropertySet`` () =
formatSourceString false """analysisKey.Headers.Item(key) <- value
""" config
|> prepend newline
|> should equal """
analysisKey.Headers.Item(key) <- value
"""

[<Test>]
let ``DotNamedIndexedPropertySet`` () =
formatSourceString false """(foo()).Item(key) <- value
""" config
|> prepend newline
|> should equal """
(foo()).Item(key) <- value
"""
4 changes: 4 additions & 0 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions src/Fantomas/SourceParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down