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

Multi-line arguments to chained method calls produce invalid code #702

Closed
evenbrenden opened this issue Feb 27, 2020 · 3 comments
Closed

Comments

@evenbrenden
Copy link

evenbrenden commented Feb 27, 2020

Issue created from fantomas-ui

Input code

    let ShowShardsCommand = 
        CommandDefinitionBuilder()
            .WithName("show")
            .WithDescription("Shows shards in a cluster")
            .WithArgument(fun builder -> 
                builder
                    .WithName("region")
                    .WithDescription("Name of the shard region from which shards should be shown")
                    .IsMandatory(true)
                    .WithSwitch("-r")
                    .WithSwitch("-R") 
                    |> ignore)
            .Build()

Output code

let ShowShardsCommand =
    CommandDefinitionBuilder().WithName("show").WithDescription("Shows shards in a cluster")
        .WithArgument
            (fun builder ->
                builder.WithName("region").WithDescription("Name of the shard region from which shards should be shown")
                       .IsMandatory(true).WithSwitch("-r").WithSwitch("-R") |> ignore).Build()

Suggested output code

    let ShowShardsCommand =
        CommandDefinitionBuilder().WithName("show").WithDescription("Shows shards in a cluster")
            .WithArgument(
                fun builder ->
                    builder.WithName("region").WithDescription("Name of the shard region from which shards should be shown")
                           .IsMandatory(true).WithSwitch("-r").WithSwitch("-R") |> ignore).Build()

Compiler error

Successive arguments should be separated by spaces or tupled, and arguments involving function or method applications should be parenthesized F# Compiler(597)

Fantomas output

The following exception occurs while formatting stdin: Fantomas.FormatConfig+FormatException: Formatted content is not valid F# code
   at Fantomas.FakeHelpers.formatContentAsync@53-3.Invoke(Boolean _arg2) in /home/evenbrenden/src/fantomas/src/Fantomas/FakeHelpers.fs:line 55
   at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvokeNoHijackCheck[a,b](AsyncActivation`1 ctxt, FSharpFunc`2 userCode, b result1) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 417
   at Fantomas.CodeFormatterImpl.isValidFSharpCode@377-6.Invoke(AsyncActivation`1 ctxt) in /home/evenbrenden/src/fantomas/src/Fantomas/CodeFormatterImpl.fs:line 377
   at Microsoft.FSharp.Control.Trampoline.Execute(FSharpFunc`2 firstAction) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 109
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.FSharp.Control.AsyncResult`1.Commit() in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 350
   at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronouslyInCurrentThread[a](CancellationToken cancellationToken, FSharpAsync`1 computation) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 882
   at Microsoft.FSharp.Control.AsyncPrimitives.RunSynchronously[T](CancellationToken cancellationToken, FSharpAsync`1 computation, FSharpOption`1 timeout) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 890
   at Microsoft.FSharp.Control.FSharpAsync.RunSynchronously[T](FSharpAsync`1 computation, FSharpOption`1 timeout, FSharpOption`1 cancellationToken) in E:\A\_work\130\s\src\fsharp\FSharp.Core\async.fs:line 1154
   at Program.processSourceString(Boolean isFsiFile, String s, FSharpChoice`2 tw, FormatConfig config) in /home/evenbrenden/src/fantomas/src/Fantomas.CoreGlobalTool/Program.fs:line 104
   at Program.stringToFile@307.Invoke(String s, String outFile, FormatConfig config) in /home/evenbrenden/src/fantomas/src/Fantomas.CoreGlobalTool/Program.fs:line 313

I'm not able to tell this apart from #498, so maybe a regression? Reproducible on 3.3.0-beta-002 and current master (cf09a21).

Options

Fantomas Next - 3.3.0-2/27/2020

Name Value
IndentOnTryWith false
IndentSpaceNum 4
KeepNewlineAfter false
MaxIfThenElseShortWidth 40
PageWidth 120
ReorderOpenDeclaration false
SemicolonAtEndOfLine false
SpaceAfterComma true
SpaceAfterSemicolon true
SpaceAroundDelimiter true
SpaceBeforeArgument true
SpaceBeforeColon false
SpaceBeforeSemicolon false
StrictMode false
@quintusm
Copy link

Personally I think the formatting of chained method code is really ugly at the moment. I would prefer if it could produce code looking more like the input code which is easily understandable and less like the suggested output code which seems to me to be hard to read.

@evenbrenden
Copy link
Author

Personally I think the formatting of chained method code is really ugly at the moment. I would prefer if it could produce code looking more like the input code which is easily understandable and less like the suggested output code which seems to me to be hard to read.

I agree, stacking all the method calls on a single column looks tidier to me too. The suggested output code is the smallest change needed to make this compile (that is, getting the opening parenthesis before the lambda on the right line) compared to the current output.

@nojaf
Copy link
Contributor

nojaf commented Aug 16, 2020

I think this is no longer an issue on the master branch.
As for the style change, you can track #501

@nojaf nojaf closed this as completed Aug 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants