From 6ec8024954e690f7638774d9b2e96effed1baca3 Mon Sep 17 00:00:00 2001 From: nojaf Date: Tue, 22 Dec 2020 21:17:46 +0100 Subject: [PATCH] Keep new line before SynExpr.DotIndexedSet. Fixes #1314. --- src/Fantomas.Tests/SynExprSetTests.fs | 55 +++++++++++++++++++++++++++ src/Fantomas/CodePrinter.fs | 1 + 2 files changed, 56 insertions(+) diff --git a/src/Fantomas.Tests/SynExprSetTests.fs b/src/Fantomas.Tests/SynExprSetTests.fs index 5c90db50fe..49d74bc4d5 100644 --- a/src/Fantomas.Tests/SynExprSetTests.fs +++ b/src/Fantomas.Tests/SynExprSetTests.fs @@ -199,3 +199,58 @@ let ``multi line DotNamedIndexedPropertySet`` () = |> string |> StringValues """ + +[] +let ``keep new line before SynExpr.DotIndexedSet, 1314`` () = + formatSourceString + false + """ + match x with + | NotificationEvent.Lint (file, warnings) -> + let uri = Path.FilePathToUri file + + diagnosticCollections.AddOrUpdate((uri, "F# Linter"), [||], (fun _ _ -> [||])) + |> ignore + + let fs = + warnings + |> List.choose + (fun w -> + w.Warning.Details.SuggestedFix + |> Option.bind + (fun f -> + let f = f.Force() + let range = fcsRangeToLsp w.Warning.Details.Range + + f + |> Option.map (fun f -> range, { Range = range; NewText = f.ToText }))) + + lintFixes.[uri] <- fs +""" + config + |> prepend newline + |> should + equal + """ +match x with +| NotificationEvent.Lint (file, warnings) -> + let uri = Path.FilePathToUri file + + diagnosticCollections.AddOrUpdate((uri, "F# Linter"), [||], (fun _ _ -> [||])) + |> ignore + + let fs = + warnings + |> List.choose + (fun w -> + w.Warning.Details.SuggestedFix + |> Option.bind + (fun f -> + let f = f.Force() + let range = fcsRangeToLsp w.Warning.Details.Range + + f + |> Option.map (fun f -> range, { Range = range; NewText = f.ToText }))) + + lintFixes.[uri] <- fs +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index ca86927eff..abe7630340 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -2737,6 +2737,7 @@ and genExpr astContext synExpr ctx = | SynExpr.Upcast _ -> genTriviaFor SynExpr_Upcast synExpr.Range | SynExpr.Downcast _ -> genTriviaFor SynExpr_Downcast synExpr.Range | SynExpr.DotIndexedGet _ -> genTriviaFor SynExpr_DotIndexedGet synExpr.Range + | SynExpr.DotIndexedSet _ -> genTriviaFor SynExpr_DotIndexedSet synExpr.Range | _ -> id) expr ctx