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

Control space in pattern by fsharp_space_before_lowercase_invocation and fsharp_space_before_uppercase_invocation #2551

Merged
merged 1 commit into from
Oct 7, 2022
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [Unreleased]

### Changed
* Control space in pattern by `fsharp_space_before_lowercase_invocation` and `fsharp_space_before_uppercase_invocation`. [fslang-design/issues/712](https://github.com/fsharp/fslang-design/issues/712)

### Fixed
* Comments in SynArgPats.NamePatPairs are lost. [#2541](https://github.com/fsprojects/fantomas/issues/2541)

## [5.1.0-alpha-004] - 2022-10-07

### Changed
Expand Down
18 changes: 12 additions & 6 deletions docs/docs/end-users/Configuration.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,18 @@ formatCode
<fantomas-setting name="fsharp_space_before_lowercase_invocation" orange></fantomas-setting>
Add a space after the name of a lowercased function and before the opening parenthesis of the first argument.
This setting influences function invocation.
This setting influences function invocation in expressions and patterns.
Default = true.
*)

formatCode
"""
value (a, b)
startTimer ()
value (a, b)
startTimer ()
match x with
| value (a, b) -> ()
"""
{ FormatConfig.Default with SpaceBeforeLowercaseInvocation = false }
(*** include-it ***)
Expand All @@ -168,15 +171,18 @@ formatCode
<fantomas-setting name="fsharp_space_before_uppercase_invocation" green gr></fantomas-setting>
Add a space after the name of a uppercase function and before the opening parenthesis of the first argument.
This setting influences function invocation.
This setting influences function invocation in expressions and patterns.
Default = false.
*)

formatCode
"""
Value(a, b)
person.ToString()
Value(a, b)
person.ToString()
match x with
| Value(a, b) -> ()
"""
{ FormatConfig.Default with SpaceBeforeUppercaseInvocation = true }
(*** include-it ***)
Expand Down
10 changes: 5 additions & 5 deletions src/Fantomas.Core.Tests/AppTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ module Caching =
lock cacheFiles.CachedNetworkData (fun _ ->
match balance with
| NotAvailable -> NotAvailable
| Cached (balance, time) ->
| Cached(balance, time) ->
if compoundBalance < 0.0m then
ReportProblem
compoundBalance
Expand Down Expand Up @@ -176,7 +176,7 @@ module Caching =
lock cacheFiles.CachedNetworkData (fun _ ->
match balance with
| NotAvailable -> NotAvailable
| Cached (balance, time) ->
| Cached(balance, time) ->
if compoundBalance < 0.0m then
ReportProblem
looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong
Expand Down Expand Up @@ -214,7 +214,7 @@ module Caching =
lock cacheFiles.CachedNetworkData (fun _ ->
match balance with
| NotAvailable -> NotAvailable
| Cached (balance, time) ->
| Cached(balance, time) ->
if compoundBalance < 0.0m then
ReportProblem compoundBalance None currency address sessionCachedNetworkData
Expand Down Expand Up @@ -251,7 +251,7 @@ module Caching =
lock cacheFiles.CachedNetworkData (fun _ ->
match balance with
| NotAvailable -> NotAvailable
| Cached (balance, time) ->
| Cached(balance, time) ->
if compoundBalance < 0.0m then
ReportProblem compoundBalance
Expand Down Expand Up @@ -726,7 +726,7 @@ module Foo =
thing
|> Map.iter (fun key value ->
match value with
| Ok (TestResult.Failure f) -> failwith ""
| Ok(TestResult.Failure f) -> failwith ""
| Error e -> failwith ""
| _ -> () // hi!
))
Expand Down
6 changes: 3 additions & 3 deletions src/Fantomas.Core.Tests/CommentTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1940,7 +1940,7 @@ let compilerOptionUsage (CompilerOption (s, tag, spec, _, _)) =
|> should
equal
"""
let compilerOptionUsage (CompilerOption (s, tag, spec, _, _)) =
let compilerOptionUsage (CompilerOption(s, tag, spec, _, _)) =
let s =
if s = "--" then
""
Expand Down Expand Up @@ -2012,7 +2012,7 @@ let compilerOptionUsage (CompilerOption (s, tag, spec, _, _)) =
|> should
equal
"""
let compilerOptionUsage (CompilerOption (s, tag, spec, _, _)) =
let compilerOptionUsage (CompilerOption(s, tag, spec, _, _)) =
let s =
if s = "--" then
""
Expand Down Expand Up @@ -2357,7 +2357,7 @@ node {
match builderOpt with
| Some builder ->
match! bc.GetCachedCheckFileResult(builder, fileName, sourceText, options) with
| Some (_, checkResults) ->
| Some(_, checkResults) ->
return Some(builder, creationDiags, Some(FSharpCheckFileAnswer.Succeeded checkResults))
| _ -> return Some(builder, creationDiags, None)
| _ -> return None // the builder wasn't ready
Expand Down
8 changes: 4 additions & 4 deletions src/Fantomas.Core.Tests/ComputationExpressionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ let s2 = seq { 0..10..100 }
let rec inorder tree =
seq {
match tree with
| Tree (x, left, right) ->
| Tree(x, left, right) ->
yield! inorder left
yield x
yield! inorder right
Expand Down Expand Up @@ -1512,10 +1512,10 @@ let private getAST log (req: HttpRequest) =
| Result.Ok ast ->
let node =
match ast with
| ParsedInput.ImplFile (ParsedImplFileInput.ParsedImplFileInput (_, _, _, _, hds, mns, _)) ->
| ParsedInput.ImplFile(ParsedImplFileInput.ParsedImplFileInput(_, _, _, _, hds, mns, _)) ->
Fantomas.AstTransformer.astToNode hds mns
| ParsedInput.SigFile (ParsedSigFileInput.ParsedSigFileInput (_, _, _, _, mns)) ->
| ParsedInput.SigFile(ParsedSigFileInput.ParsedSigFileInput(_, _, _, _, mns)) ->
Fantomas.AstTransformer.sigAstToNode mns
|> Encoders.nodeEncoder
Expand Down Expand Up @@ -2306,7 +2306,7 @@ let generateUnionCases =
let! (tyRes, line, lines) = getParseResultsForFile fileName pos
match! generateCases tyRes pos lines line |> Async.map Ok with
| CoreResponse.Res (insertString: string, insertPosition) ->
| CoreResponse.Res(insertString: string, insertPosition) ->
return
[ { SourceDiagnostic = Some diagnostic
File = codeActionParams.TextDocument
Expand Down
6 changes: 3 additions & 3 deletions src/Fantomas.Core.Tests/ControlStructureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ let function1 x y =
raise (OuterError("outer"))
with
| Failure _ -> ()
| InnerError (str) -> printfn "Error1 %s" str
| InnerError(str) -> printfn "Error1 %s" str
finally
printfn "Always print this."
"""
Expand Down Expand Up @@ -629,8 +629,8 @@ let genPropertyWithGetSet astContext (b1, b2) rangeOfMember =
"""
let genPropertyWithGetSet astContext (b1, b2) rangeOfMember =
match b1, b2 with
| PropertyBinding (ats, px, ao, isInline, mf1, PatLongIdent (ao1, s1, ps1, _), e1),
PropertyBinding (_, _, _, _, _, PatLongIdent (ao2, _, ps2, _), e2) ->
| PropertyBinding(ats, px, ao, isInline, mf1, PatLongIdent(ao1, s1, ps1, _), e1),
PropertyBinding(_, _, _, _, _, PatLongIdent(ao2, _, ps2, _), e2) ->
let prefix =
genPreXmlDoc px
+> genAttributes astContext ats
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.Core.Tests/DotGetTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ module Services =
initial
)
.Resolve
| Storage.EventStore (gateway, cache) ->
| Storage.EventStore(gateway, cache) ->
let accessStrategy = Equinox.EventStore.AccessStrategy.RollingSnapshots snapshot
let cacheStrategy =
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.Core.Tests/FunctionDefinitionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ type U = X of int
let f =
fun x ->
match x with
| X (x) -> x
| X(x) -> x
"""

[<Test>]
Expand Down
4 changes: 2 additions & 2 deletions src/Fantomas.Core.Tests/KeepIndentInBranchTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ let rec getEndCol (r: Range) (tokenizer: FSharpLineTokenizer) lexState =
/// Find out the end token
let rec getEndCol (r: Range) (tokenizer: FSharpLineTokenizer) lexState =
match tokenizer.ScanToken(!lexState) with
| Some (tok), state ->
| Some(tok), state ->
Debug.WriteLine("End token: {0}", sprintf "%A" tok |> box)

if tok.RightColumn >= r.EndColumn && isSignificantToken tok then
Expand Down Expand Up @@ -785,7 +785,7 @@ module Foo =
| Error e ->
printfn ""
2
| Ok (thing, instructions) ->
| Ok(thing, instructions) ->

log.LogInformation("")

Expand Down
4 changes: 2 additions & 2 deletions src/Fantomas.Core.Tests/LambdaTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ let init =
let init =
addDateTimeConverter
(fun dt -> Date(dt.Year, dt.Month, dt.Day))
(fun (Date (y, m, d)) -> System.DateTime(y, m, d))
(fun (Date(y, m, d)) -> System.DateTime(y, m, d))
"""

[<Test>]
Expand Down Expand Up @@ -787,7 +787,7 @@ let ``desugared union case, 1631`` () =
|> should
equal
"""
col (fun (ArgInfo (ats, so, isOpt), t) -> sepNone)
col (fun (ArgInfo(ats, so, isOpt), t) -> sepNone)
"""

[<Test>]
Expand Down
18 changes: 9 additions & 9 deletions src/Fantomas.Core.Tests/LetBindingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ let genSigModuleDeclList astContext node =
match node with
| [ x ] -> genSigModuleDecl astContext x

| SigOpenL (xs, ys) ->
| SigOpenL(xs, ys) ->
let sepXsAndYs =
match List.tryHead ys with
| Some hs ->
Expand Down Expand Up @@ -774,14 +774,14 @@ let useEntries month year =
let income =
events
|> Seq.choose (function
| Event.AddIncome (ai) when (filter ai.Created && isNotCancelled ai.Id) -> Some ai
| Event.AddIncome(ai) when (filter ai.Created && isNotCancelled ai.Id) -> Some ai
| _ -> None)
|> sortMapAndToArray

let expenses =
events
|> Seq.choose (function
| Event.AddExpense (ae) when (filter ae.Created && isNotCancelled ae.Id) -> Some ae
| Event.AddExpense(ae) when (filter ae.Created && isNotCancelled ae.Id) -> Some ae
| _ -> None)
|> sortMapAndToArray

Expand Down Expand Up @@ -812,14 +812,14 @@ let useEntries month year =
let income =
events
|> Seq.choose (function
| Event.AddIncome (ai) when (filter ai.Created && isNotCancelled ai.Id) -> Some ai
| Event.AddIncome(ai) when (filter ai.Created && isNotCancelled ai.Id) -> Some ai
| _ -> None)
|> sortMapAndToArray

let expenses =
events
|> Seq.choose (function
| Event.AddExpense (ae) when (filter ae.Created && isNotCancelled ae.Id) -> Some ae
| Event.AddExpense(ae) when (filter ae.Created && isNotCancelled ae.Id) -> Some ae
| _ -> None)
|> sortMapAndToArray

Expand Down Expand Up @@ -925,8 +925,8 @@ let useOverviewPerMonth () =
events
|> List.choose (fun msg ->
match msg with
| Event.AddIncome ({ Created = created })
| Event.AddExpense ({ Created = created }) -> Some(created.Month, created.Year)
| Event.AddIncome({ Created = created })
| Event.AddExpense({ Created = created }) -> Some(created.Month, created.Year)
| _ -> None)
|> List.distinct
|> List.sort
Expand Down Expand Up @@ -962,8 +962,8 @@ let useOverviewPerMonth () =
events
|> List.choose (fun msg ->
match msg with
| Event.AddIncome ({ Created = created })
| Event.AddExpense ({ Created = created }) -> Some(created.Month, created.Year)
| Event.AddIncome({ Created = created })
| Event.AddExpense({ Created = created }) -> Some(created.Month, created.Year)
| _ -> None)
|> List.distinct
|> List.sort
Expand Down
4 changes: 2 additions & 2 deletions src/Fantomas.Core.Tests/MultiLineLambdaClosingNewlineTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ let expr =
es
(fun e ->
match e with
| Paren (_, Lambda _, _) -> !- "lambda"
| Paren(_, Lambda _, _) -> !- "lambda"
| _ -> genExpr astContext e
)
"""
Expand Down Expand Up @@ -859,7 +859,7 @@ module Foo =
thing
|> Map.iter (fun key value ->
match value with
| Ok (TestResult.Failure f) -> failwith ""
| Ok(TestResult.Failure f) -> failwith ""
| Error e -> failwith ""
| _ -> () // hi!
)
Expand Down
4 changes: 2 additions & 2 deletions src/Fantomas.Core.Tests/OperatorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,8 +1002,8 @@ let MethInfosEquivByNameAndSig erasureFlag ignoreFinal g amap m minfo minfo2 =
/// Used to hide/filter members from base classes based on signature
let MethInfosEquivByNameAndSig erasureFlag ignoreFinal g amap m minfo minfo2 =
MethInfosEquivByNameAndPartialSig erasureFlag ignoreFinal g amap m minfo minfo2
&& let (CompiledSig (_, retTy, formalMethTypars, _)) = CompiledSigOfMeth g amap m minfo in
let (CompiledSig (_, retTy2, formalMethTypars2, _)) =
&& let (CompiledSig(_, retTy, formalMethTypars, _)) = CompiledSigOfMeth g amap m minfo in
let (CompiledSig(_, retTy2, formalMethTypars2, _)) =
CompiledSigOfMeth g amap m minfo2 in
match retTy, retTy2 with
Expand Down
Loading