Skip to content

Commit

Permalink
Control semicolon in pattern list via setting. Fixes fsprojects#1793. (
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf authored Jul 1, 2021
1 parent 03e8d07 commit 0323229
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 12 deletions.
88 changes: 88 additions & 0 deletions src/Fantomas.Tests/RecordTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1444,3 +1444,91 @@ let x = { actual = 6 y = x }

let y = { actual = 6; y = x }
"""

[<Test>]
let ``multiline records in pattern list should not have semicolon by default, 1793`` () =
formatSourceString
false
"""
match entities with
| [ { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d1"
Type = Elephant }
{ Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d2"
Type = Elephant }
{ Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d3"
Type = Elephant } ] -> ()
| _ -> ()
"""
config
|> prepend newline
|> should
equal
"""
match entities with
| [ { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d1"
Type = Elephant }
{ Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d2"
Type = Elephant }
{ Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d3"
Type = Elephant } ] -> ()
| _ -> ()
"""

[<Test>]
let ``multiline records in pattern list should have semicolon`` () =
formatSourceString
false
"""
match entities with
| [ { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d1"
Type = Elephant }
{ Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d2"
Type = Elephant }
{ Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d3"
Type = Elephant } ] -> ()
| _ -> ()
"""
{ config with
SemicolonAtEndOfLine = true }
|> prepend newline
|> should
equal
"""
match entities with
| [ { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d1";
Type = Elephant };
{ Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d2";
Type = Elephant };
{ Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d3";
Type = Elephant } ] -> ()
| _ -> ()
"""

[<Test>]
let ``multiline records in pattern array should not have semicolon by default`` () =
formatSourceString
false
"""
match entities with
| [| { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d1"
Type = Elephant }
{ Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d2"
Type = Elephant }
{ Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d3"
Type = Elephant } |] -> ()
| _ -> ()
"""
config
|> prepend newline
|> should
equal
"""
match entities with
| [| { Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d1"
Type = Elephant }
{ Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d2"
Type = Elephant }
{ Key = "0031ff53-e59b-49e3-8e0f-53f72a3890d3"
Type = Elephant } |] -> ()
| _ -> ()
"""
28 changes: 16 additions & 12 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4863,20 +4863,24 @@ and genPat astContext pat =

expressionFitsOnRestOfLine short long
| PatSeq (PatList, ps) ->
ifElse
ps.IsEmpty
(sepOpenLFixed +> sepCloseLFixed)
(sepOpenL
+> atCurrentColumn (colAutoNlnSkip0 sepSemi ps (genPat astContext))
+> sepCloseL)
let genPats =
let short =
colAutoNlnSkip0 sepSemi ps (genPat astContext)

let long = col sepSemiNln ps (genPat astContext)
expressionFitsOnRestOfLine short long

ifElse ps.IsEmpty (sepOpenLFixed +> sepCloseLFixed) (sepOpenL +> atCurrentColumn genPats +> sepCloseL)

| PatSeq (PatArray, ps) ->
ifElse
ps.IsEmpty
(sepOpenAFixed +> sepCloseAFixed)
(sepOpenA
+> atCurrentColumn (colAutoNlnSkip0 sepSemi ps (genPat astContext))
+> sepCloseA)
let genPats =
let short =
colAutoNlnSkip0 sepSemi ps (genPat astContext)

let long = col sepSemiNln ps (genPat astContext)
expressionFitsOnRestOfLine short long

ifElse ps.IsEmpty (sepOpenAFixed +> sepCloseAFixed) (sepOpenA +> atCurrentColumn genPats +> sepCloseA)

| PatRecord xs ->
let smallRecordExpr =
Expand Down

0 comments on commit 0323229

Please sign in to comment.