From 32882008922d1106ca05bbb70eefbb0188c5b172 Mon Sep 17 00:00:00 2001 From: Florian Verdonck Date: Tue, 10 Aug 2021 21:02:27 +0200 Subject: [PATCH] Remove SynPat_Or as trivia node candidate. (#1860) * Remove SynPat_Or as trivia node candidate. Fixes #1855. Fixes #1677. * Update to Paket 6 and add global.json. --- .config/dotnet-tools.json | 2 +- global.json | 6 +++ src/Fantomas.Tests/PatternMatchingTests.fs | 44 ++++++++++++++++++++++ src/Fantomas/AstTransformer.fs | 5 +-- src/Fantomas/TriviaTypes.fs | 2 +- 5 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 global.json diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 821ff48b92..5e18dd241c 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "paket": { - "version": "6.0.0-rc006", + "version": "6.0.0", "commands": [ "paket" ] diff --git a/global.json b/global.json new file mode 100644 index 0000000000..a11dc73c75 --- /dev/null +++ b/global.json @@ -0,0 +1,6 @@ +{ + "sdk": { + "version": "5.0.0", + "rollForward": "minor" + } +} \ No newline at end of file diff --git a/src/Fantomas.Tests/PatternMatchingTests.fs b/src/Fantomas.Tests/PatternMatchingTests.fs index 0f6f664bef..cce13ad41d 100644 --- a/src/Fantomas.Tests/PatternMatchingTests.fs +++ b/src/Fantomas.Tests/PatternMatchingTests.fs @@ -1965,3 +1965,47 @@ let foo x = let y = x * x * (x + 1) x """ + +[] +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" +""" + +[] +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 +""" diff --git a/src/Fantomas/AstTransformer.fs b/src/Fantomas/AstTransformer.fs index 4310e0a20c..107ea3bd5a 100644 --- a/src/Fantomas/AstTransformer.fs +++ b/src/Fantomas/AstTransformer.fs @@ -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) -> diff --git a/src/Fantomas/TriviaTypes.fs b/src/Fantomas/TriviaTypes.fs index ef65a70d12..6040323322 100644 --- a/src/Fantomas/TriviaTypes.fs +++ b/src/Fantomas/TriviaTypes.fs @@ -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