Skip to content

Commit

Permalink
Fix for fsprojects#498
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Oct 12, 2019
1 parent 906b81c commit 6b2d468
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 5 deletions.
63 changes: 63 additions & 0 deletions src/Fantomas.Tests/LongIdentWithDotsTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,67 @@ let ``force newline by adding comments`` () =
.UseCaching() //
.UseSql() //
.UseMeh()
"""

[<Test>]
let ``method call on multiple lines`` () =
formatSourceString false """module Program
[<EntryPoint>]
let main _ =
try
try
Config.Logger.configure ()
let config =
ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.Build()
WebHostBuilder()
.UseConfiguration(config)
.UseKestrel()
.UseSerilog()
.ConfigureAppConfiguration(Action<WebHostBuilderContext, IConfigurationBuilder> configureAppConfiguration)
.ConfigureServices(Action<WebHostBuilderContext, IServiceCollection> configureServices)
.Configure(Action<IApplicationBuilder> configureApp)
.Build()
.Run()
|> ignore
0
with
| ex ->
Log.Fatal(ex, "Service terminated unexpectedly")
1
finally
Log.CloseAndFlush()
""" config
|> prepend newline
|> should equal """
module Program
[<EntryPoint>]
let main _ =
try
try
Config.Logger.configure()
let config = ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).Build()
WebHostBuilder().UseConfiguration(config).UseKestrel().UseSerilog()
.ConfigureAppConfiguration
(Action<WebHostBuilderContext, IConfigurationBuilder> configureAppConfiguration)
.ConfigureServices(Action<WebHostBuilderContext, IServiceCollection> configureServices)
.Configure(Action<IApplicationBuilder> configureApp).Build().Run() |> ignore
0
with ex ->
Log.Fatal(ex, "Service terminated unexpectedly")
1
finally
Log.CloseAndFlush()
"""
4 changes: 2 additions & 2 deletions src/Fantomas.Tests/OperatorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ let ``should break on . operator and keep indentation``() =
|> should equal """let pattern =
(x + y)
.Replace
(seperator + "**" + seperator,
replacementSeparator + "(.|?" + replacementSeparator + ")?")
(seperator + "**" + seperator,
replacementSeparator + "(.|?" + replacementSeparator + ")?")
.Replace("**" + seperator, ".|(?<=^|" + replacementSeparator + ")")
"""

Expand Down
11 changes: 8 additions & 3 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -988,9 +988,14 @@ and genExpr astContext synExpr =
|> Option.map (snd >> (fun lid -> genTrivia lid.idRange))
|> Option.defaultValue (id)

let writeExpr = ((genTriviaOfIdent (!- (sprintf ".%s" s))) +> ifElse (hasParenthesis e) sepNone sepSpace
+> (fun ctx -> ctx |> ifElse (futureNlnCheck (genExpr astContext e) ctx) sepNln sepNone)
+> genExpr astContext e)
let hasParenthe = hasParenthesis e
let writeExpr = ((genTriviaOfIdent (!- (sprintf ".%s" s))) +> ifElse hasParenthe sepNone sepSpace
+> (fun ctx ->
let hasFutureNln = futureNlnCheck (genExpr astContext e) ctx
let whenNln = ifElse hasParenthe (indent +> sepNln +> genExpr astContext e +> unindent) (sepNln +> genExpr astContext e)
ctx
|> ifElse hasFutureNln whenNln (genExpr astContext e)
))

let addNewlineIfNeeded (ctx: Context) =
if ctx.Config.KeepNewlineAfter then
Expand Down

0 comments on commit 6b2d468

Please sign in to comment.