diff --git a/src/Fantomas.Tests/ComputationExpressionTests.fs b/src/Fantomas.Tests/ComputationExpressionTests.fs index 824e06af7f..1b5d7d765c 100644 --- a/src/Fantomas.Tests/ComputationExpressionTests.fs +++ b/src/Fantomas.Tests/ComputationExpressionTests.fs @@ -2276,3 +2276,56 @@ let setup = value) } """ + +[] +let ``keep new line before match bang, 1313`` () = + formatSourceString + false + """ + /// a codefix that generates union cases for an incomplete match expression + let generateUnionCases = + ifDiagnosticByMessage + (fun diagnostic codeActionParams -> + asyncResult { + let! (tyRes, line, lines) = getParseResultsForFile fileName pos + + match! generateCases tyRes pos lines line |> Async.map Ok with + | CoreResponse.Res (insertString: string, insertPosition) -> + return + [ { SourceDiagnostic = Some diagnostic + File = codeActionParams.TextDocument + Title = "Generate union pattern match cases" + Edits = [| { Range = range; NewText = replaced } |] + Kind = Fix } ] + + | _ -> return [] + } + |> AsyncResult.foldResult id (fun _ -> [])) + "Incomplete pattern matches on this expression. For example" +""" + config + |> prepend newline + |> should + equal + """ +/// a codefix that generates union cases for an incomplete match expression +let generateUnionCases = + ifDiagnosticByMessage + (fun diagnostic codeActionParams -> + asyncResult { + let! (tyRes, line, lines) = getParseResultsForFile fileName pos + + match! generateCases tyRes pos lines line |> Async.map Ok with + | CoreResponse.Res (insertString: string, insertPosition) -> + return + [ { SourceDiagnostic = Some diagnostic + File = codeActionParams.TextDocument + Title = "Generate union pattern match cases" + Edits = [| { Range = range; NewText = replaced } |] + Kind = Fix } ] + + | _ -> return [] + } + |> AsyncResult.foldResult id (fun _ -> [])) + "Incomplete pattern matches on this expression. For example" +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 27f1d17e9c..ca86927eff 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -2716,6 +2716,7 @@ and genExpr astContext synExpr ctx = | SynExpr.Lambda _ -> genTriviaFor SynExpr_Lambda synExpr.Range | SynExpr.ForEach _ -> genTriviaFor SynExpr_ForEach synExpr.Range | SynExpr.Match _ -> genTriviaFor SynExpr_Match synExpr.Range + | SynExpr.MatchBang _ -> genTriviaFor SynExpr_MatchBang synExpr.Range | SynExpr.YieldOrReturn _ -> genTriviaFor SynExpr_YieldOrReturn synExpr.Range | SynExpr.YieldOrReturnFrom _ -> genTriviaFor SynExpr_YieldOrReturnFrom synExpr.Range | SynExpr.TryFinally _ -> genTriviaFor SynExpr_TryFinally synExpr.Range