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

Keep newline above match bang. #1315

Merged
merged 1 commit into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/Fantomas.Tests/ComputationExpressionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2276,3 +2276,56 @@ let setup =
value)
}
"""

[<Test>]
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"
"""
1 change: 1 addition & 0 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down