Skip to content

Commit

Permalink
Indent and add newline for multiline do(bang) expressions. Fixes fspr…
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Nov 21, 2020
1 parent f66f4a1 commit 466c6f5
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 13 deletions.
16 changes: 8 additions & 8 deletions src/Fantomas.Tests/CompilerDirectivesTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,10 @@ let internal UpdateStrongNaming (assembly: AssemblyDefinition) (key: StrongNameK
match key with
| None ->
#endif
assembly.MainModule.Attributes <- assembly.MainModule.Attributes &&& (~~~ModuleAttributes.StrongNameSigned)
assemblyName.HasPublicKey <- false
assemblyName.PublicKey <- null
assemblyName.PublicKeyToken <- null
assembly.MainModule.Attributes <- assembly.MainModule.Attributes &&& (~~~ModuleAttributes.StrongNameSigned)
assemblyName.HasPublicKey <- false
assemblyName.PublicKey <- null
assemblyName.PublicKeyToken <- null
#if NETCOREAPP2_0
#else
| Some key' ->
Expand Down Expand Up @@ -479,10 +479,10 @@ let internal UpdateStrongNaming (assembly: AssemblyDefinition) (key: StrongNameK
#endif
assembly.MainModule.Attributes <- assembly.MainModule.Attributes &&& (~~~ModuleAttributes.StrongNameSigned)
assemblyName.HasPublicKey <- false
assemblyName.PublicKey <- null
assemblyName.PublicKeyToken <- null
assembly.MainModule.Attributes <- assembly.MainModule.Attributes &&& (~~~ModuleAttributes.StrongNameSigned)
assemblyName.HasPublicKey <- false
assemblyName.PublicKey <- null
assemblyName.PublicKeyToken <- null
#if NETCOREAPP2_0
#else
Expand Down
72 changes: 71 additions & 1 deletion src/Fantomas.Tests/ComputationExpressionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,8 @@ let sendPushNotifications =
with :? WebPushException as wpex ->
log.LogError(sprintf "Couldn't send notification to %s, %A" user.UserId wpex)
do! filterSubscriptionsAndPersist
do!
filterSubscriptionsAndPersist
managementToken
user.UserId
subscriptions
Expand Down Expand Up @@ -1872,3 +1873,72 @@ let password =
with_validators (String.exists Char.IsUpper) (String.exists Char.IsDigit) (fun s -> s.Length >= 6)
}
"""

[<Test>]
let ``multiline do bang`` () =
formatSourceString false """
type ProjectController(checker: FSharpChecker) =
member x.LoadWorkspace (files: string list) (tfmForScripts: FSIRefs.TFM) onProjectLoaded (generateBinlog: bool) =
async {
match Environment.workspaceLoadDelay () with
| delay when delay > TimeSpan.Zero ->
do! Async.Sleep(
Environment.workspaceLoadDelay().TotalMilliseconds
|> int
)
| _ -> ()
return true
}
""" { config with IndentSize = 2 }
|> prepend newline
|> should equal """
type ProjectController(checker: FSharpChecker) =
member x.LoadWorkspace (files: string list) (tfmForScripts: FSIRefs.TFM) onProjectLoaded (generateBinlog: bool) =
async {
match Environment.workspaceLoadDelay () with
| delay when delay > TimeSpan.Zero ->
do!
Async.Sleep(
Environment.workspaceLoadDelay().TotalMilliseconds
|> int
)
| _ -> ()
return true
}
"""

[<Test>]
let ``multiline do`` () =
formatSourceString false """
type ProjectController(checker: FSharpChecker) =
member x.LoadWorkspace (files: string list) (tfmForScripts: FSIRefs.TFM) onProjectLoaded (generateBinlog: bool) =
async {
match Environment.workspaceLoadDelay () with
| delay when delay > TimeSpan.Zero ->
do NonAsync.Sleep( Environment.workspaceLoadDelay().TotalMilliseconds |> int )
| _ -> ()
return true
}
""" { config with IndentSize = 2 }
|> prepend newline
|> should equal """
type ProjectController(checker: FSharpChecker) =
member x.LoadWorkspace (files: string list) (tfmForScripts: FSIRefs.TFM) onProjectLoaded (generateBinlog: bool) =
async {
match Environment.workspaceLoadDelay () with
| delay when delay > TimeSpan.Zero ->
do
NonAsync.Sleep(
Environment.workspaceLoadDelay().TotalMilliseconds
|> int
)
| _ -> ()
return true
}
"""
7 changes: 4 additions & 3 deletions src/Fantomas.Tests/LetBindingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1137,9 +1137,10 @@ do
""" config
|> prepend newline
|> should equal """
do let rec f = ()
and g = () in
()
do
let rec f = ()
and g = () in
()
"""

[<Test>]
Expand Down
4 changes: 3 additions & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,9 @@ and genExpr astContext synExpr ctx =
| YieldFrom
| Yield
| Return
| ReturnFrom -> autoIndentAndNlnIfExpressionExceedsPageWidth (genExpr astContext e)
| ReturnFrom
| Do
| DoBang -> autoIndentAndNlnIfExpressionExceedsPageWidth (genExpr astContext e)
| _ -> genExpr astContext e)

| ConstExpr (c, r) -> genConst c r
Expand Down

0 comments on commit 466c6f5

Please sign in to comment.