julia-vscode / DocumentFormat.jl

Auto-formatter for Julia
Other
62 stars 18 forks source link

Support for multi-line statements/lists. #71

Closed norru closed 2 years ago

norru commented 4 years ago

Here's a trivial example of code that DocumentFormat.jl doesn't handle in any way (doesn't even indent correctly):

function example(a, b, c)
    a(b, "first", 
                    c,
            "third",
        "fourth")
end

I would expect either:

function example(a, b, c)
    a(b, "first", c, "third", "fourth")
end

If the formatted line is within margins, or

function example(a, b, c)
    a(b,
      "first",
      c,
      "third",
      "fourth")
end

if it doesn't. More sophisticated algorithms could do something like this as well

function example(a, b, c)
    a(b, "first", c, 
      "third", "fourth")
end

Even if we have the option of "not touching line breaks" (which is also controversial), I would expect this result:

function example(a, b, c)
    a(b, "first", 
      c,
      "third",
      "fourth")
end

And this should be done for any kind of sequences, including arguments, export clauses etc, possibly with a separate enable/disable option for each.

By the way I am not making this stuff up, I've seen it working many times. Every language I have ever used had a least one formatter tool which supported this (including Juila, which has this supported in JuliaFormatter.jl)