microsoft / powerquery-formatter

MIT License
38 stars 12 forks source link

[BUG] Formatted code is too expanded #60

Closed HomelessCoder closed 2 years ago

HomelessCoder commented 2 years ago

Expected behavior The code is formatted and well-readable.

Actual behavior The code is formatted, but not readable or too expanded.

To Reproduce

Additional context This is a simple example. We have a file with ~250 rows, which has grown to 100%. The issue began a few days ago. Not sure when exactly, but I guess on the powerquery.vscode-powerquery extension update from 08/09/2022, 16:30:25. image

Could you do something with this, please? Would be nice to have some formatting settings at least to disable such an over-extended version.

Thanks!

JordanBoltonMN commented 2 years ago

Could you give me the exact version of the extension that's being used? You can get the exact version of the extension by bringing up the list of installed extensions and hovering over it:

image

HomelessCoder commented 2 years ago

Seems the same as yours - 0.1.44 image

JordanBoltonMN commented 2 years ago

Strange. It appears that there's something more to it than the sample code provided, because this is how it formats your code as an expression:

let
    validateUrlScheme = (url as text) as text =>
        if (Uri.Parts(url)[Scheme] <> "https") then
            error "Url scheme must be HTTPS"
        else
            url
in
    1

And as a section document:

section foobar;

validateUrlScheme = (url as text) as text =>
    if (Uri.Parts(url)[Scheme] <> "https") then
        error "Url scheme must be HTTPS"
    else
        url;

Does this match with your experience? It could be that you're code is a snippet of something larger which doesn't give the full context. For example one variable used during formatting is line length, and if it's a snippet it probably had additional indentation.

HomelessCoder commented 2 years ago

It's a part of the larger code, yes. But I've just created a new file:

image image


The same behavior with a fresh vscode and the only extension installed :(

image

JordanBoltonMN commented 2 years ago

Okay, I think I know what the difference is. Under the VSCode extension what happens if you turn on the experimental checkbox?

image

HomelessCoder commented 2 years ago

Oh, you're right! Much better now :+1: Still, a completely different format compared to the previous version, so I have the whole file changed in git...

I understand that the vscode extension is actively developing, and I appreciate your efforts. But could you clarify if the format/code style will be subject to further big changes? I mean, git tracking is getting a bit confusing, and maybe we should consider stopping using auto-formatting on save for a while.

JordanBoltonMN commented 2 years ago

We planned one big formatter change, though the non-experimental mode seems to have a regression regarding verticality. I'd recommend using the experimental mode as it's closer to what the intended format is going to be here on out.

HomelessCoder commented 2 years ago

Ok, thanks!

Do you think it's worth keeping this ticket open to track the progress on the non-experimental mode? If not - I don't mind if you close it.

JordanBoltonMN commented 2 years ago

I'm going to close it as we'll be making the experimental formatter the default formatter. Thank for bringing the issue up to begin with, it helped us re-prioritize the experimental formatter.