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

Error formatting defines #if (!DEBUG) ... #endif (no #else) #2098

Closed
1 of 3 tasks
kojo12228 opened this issue Feb 15, 2022 · 6 comments · Fixed by #2099
Closed
1 of 3 tasks

Error formatting defines #if (!DEBUG) ... #endif (no #else) #2098

kojo12228 opened this issue Feb 15, 2022 · 6 comments · Fixed by #2099

Comments

@kojo12228
Copy link

Issue created from fantomas-online

Code

namespace PmaBolero.Client

open Microsoft.AspNetCore.Components.WebAssembly.Hosting
open Microsoft.Extensions.DependencyInjection.Extensions
open Bolero.Remoting.Client

module Program =

    [<EntryPoint>]
    let Main args =
        let builder = WebAssemblyHostBuilder.CreateDefault(args)
        builder.RootComponents.Add<Pages.Main.MyApp>("#main")
        builder.Services
            .AddRemoting(builder.HostEnvironment)
            .Services
#if (!DEBUG)
            .RemoveAll<Microsoft.Extensions.Http.IHttpMessageHandlerBuilderFilter>()
#endif
            |> ignore
        builder.Build().RunAsync() |> ignore
        0

Error

System.Exception: Fantomas is trying to format the input multiple times due to the detect of multiple defines.
There is a problem with merging all the code back together.
[] has 2 fragments
[DEBUG] has 3 fragments
Please raise an issue at https://fsprojects.github.io/fantomas-tools/#/fantomas/preview.
   at Microsoft.FSharp.Core.PrintfModule.PrintFormatToStringThenFail@1439.Invoke(String message) in D:\a\_work\1\s\src\fsharp\FSharp.Core\printf.fs:line 1439
   at Fantomas.CodeFormatterImpl.format@410-3.Invoke(FSharpList`1 _arg2) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/CodeFormatterImpl.fs:line 436
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, b result1, FSharpFunc`2 userCode) in D:\a\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 465
   at Fantomas.Async.map@167-2.Invoke(AsyncActivation`1 ctxt) in /home/runner/work/fantomas-tools/fantomas-tools/.deps/fantomas/src/Fantomas/Utils.fs:line 167
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in D:\a\_work\1\s\src\fsharp\FSharp.Core\async.fs:line 105

Problem description

Please describe here the Fantomas problem you encountered.
Check out our Contribution Guidelines.

Trying to format ASP.NET-style code which uses #if (!DEBUG) to remove certain logging. Originally I was using #if RELEASE and found out this isn't the way to go about it.

Happy to try and fix this if you can point me in the right direction.

Extra information

  • The formatted result breaks by code.
  • The formatted result gives compiler warnings.
  • I or my company would be willing to help fix this.

Options

Fantomas master branch at 1/1/1990

Default Fantomas configuration

Did you know that you can ignore files when formatting from fantomas-tool or the FAKE targets by using a .fantomasignore file?

@nojaf
Copy link
Contributor

nojaf commented Feb 15, 2022

Hello, thank you for reporting this problem!
I noticed it is a trivia problem, slightly easier to detect when changing the #if to a comment.
(Sample).

The solution will probably be something similar to the fix of #2063.
I'll take a closer look later this week.

@nojaf
Copy link
Contributor

nojaf commented Feb 16, 2022

The problem was indeed very similar.
Would you like to have a release with this fix?

@kojo12228
Copy link
Author

kojo12228 commented Feb 16, 2022

Fantastic, no rush as it is by no means a critical project but yes a release would be appreciated, I'll continue testing my Bolero project when the fix is in.

@nojaf
Copy link
Contributor

nojaf commented Feb 16, 2022

Great, I'll probably pick this up on Friday.

@kojo12228
Copy link
Author

Thanks, using 4.6.5 I was able to format my project!

@nojaf
Copy link
Contributor

nojaf commented Feb 19, 2022

Thanks for confirming!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants