Skip to content

Commit

Permalink
Keep newline above match bang. Fixes fsprojects#1313.
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Dec 22, 2020
1 parent aac3975 commit 013e7a2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
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

0 comments on commit 013e7a2

Please sign in to comment.