Skip to content

Commit

Permalink
Remove SynPat_Or as trivia node candidate. (fsprojects#1860)
Browse files Browse the repository at this point in the history
* Remove SynPat_Or as trivia node candidate. Fixes fsprojects#1855. Fixes fsprojects#1677.

* Update to Paket 6 and add global.json.
  • Loading branch information
nojaf committed Aug 10, 2021
1 parent c211ee3 commit 3288200
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"paket": {
"version": "6.0.0-rc006",
"version": "6.0.0",
"commands": [
"paket"
]
Expand Down
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "5.0.0",
"rollForward": "minor"
}
}
44 changes: 44 additions & 0 deletions src/Fantomas.Tests/PatternMatchingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1965,3 +1965,47 @@ let foo x =
let y = x * x * (x + 1)
x
"""

[<Test>]
let ``comment after multi-option match, 1855`` () =
formatSourceString
false
"""
match x with
| "a" // still here
| "b" // VANISHES
| "c" -> "c"
"""
config
|> prepend newline
|> should
equal
"""
match x with
| "a" // still here
| "b" // VANISHES
| "c" -> "c"
"""

[<Test>]
let ``comment after SynPat.Or in pattern match, 1677`` () =
formatSourceString
false
"""
match v with
| x
| y // comment
| z -> 42
| _ -> 0
"""
config
|> prepend newline
|> should
equal
"""
match v with
| x
| y // comment
| z -> 42
| _ -> 0
"""
5 changes: 2 additions & 3 deletions src/Fantomas/AstTransformer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -850,13 +850,12 @@ module private Ast =
yield! nodes
yield! (visitSynAttributeLists range attrs) ]
|> finalContinuation)
| SynPat.Or (synPat, synPat2, range) ->
| SynPat.Or (synPat, synPat2, _range) ->
let continuations: ((TriviaNodeAssigner list -> TriviaNodeAssigner list) -> TriviaNodeAssigner list) list =
[ visit synPat; visit synPat2 ]

let finalContinuation (nodes: TriviaNodeAssigner list list) : TriviaNodeAssigner list =
mkNode SynPat_Or range :: (List.collect id nodes)
|> finalContinuation
List.collect id nodes |> finalContinuation

Continuation.sequence continuations finalContinuation
| SynPat.Ands (pats, range) ->
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas/TriviaTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ type FsAstType =
| SynPat_Named
| SynPat_Typed
| SynPat_Attrib
| SynPat_Or
// | SynPat_Or, use the inner patterns instead
| SynPat_Ands
| SynPat_LongIdent
| SynPat_Tuple
Expand Down

0 comments on commit 3288200

Please sign in to comment.