microsoft / AL

Home of the Dynamics 365 Business Central AL Language extension for Visual Studio Code. Used to track issues regarding the latest version of the AL compiler and developer tools available in the Visual Studio Code Marketplace or as part of the AL Developer Preview builds for Dynamics 365 Business Central.
MIT License
718 stars 242 forks source link

Autoformat tends to spread parameters into 2 lines on save #7785

Open bjarkihall opened 6 days ago

bjarkihall commented 6 days ago

1. Describe the bug When saving in vscode and the auto-format kicks in, the parameters of a procedure tend to split from 1 into 2 lines.

2. To Reproduce Save a file you're working on and eventually you will run into it if you have formatOnSave turned on, which is the default. It's hard to describe a guaranteed reproduction steps, but I'm hoping by registering the issue other people cast their vote and might have a small reproducible example.

Some people I've talked to think it's related to pressing cancel when the formatter is taking a long time and blocking them from saving the file. I thought it was related to big files, but today it just happened on a file which had 255 lines to most of its procedures and I don't recall cancelling the format (regardless, cancelling auto-format shouldn't leave any half-done changes).

I think it tends to be more likely to happen if there are many parameters with long names on the procedure, like the formatter considers the line to have too many characters and tries to break it down into 2 shorter ones?

3. Expected behavior I would expect the formatter to only be concerned with whitespace (which is the case here), but when it comes to parameters, it shouldn't try to do too much (max-characters-per-line shouldn't be of its concern).

Single space after the var-keyword, colon and semi-colon:

procedure Foo(var AParameter: Integer; BParameter: Text; CParameter: Boolean; var DParameter: DateTime) ReturnValue: Text;
var
    LocalVariable: Text;
begin
end;

But I'd also expect parameters in separate lines to be respected, if a developer intentionally spread them:

procedure Foo(
    var AParameter: Integer;
    BParameter: Text;
    CParameter: Boolean;
    var DParameter: DateTime
) ReturnValue: Text;
var
    LocalVariable: Text;
begin
end;

The formatter itself shouldn't start spreading the parameters into more lines.

4. Actual behavior Sometimes the parameters end up like this, with parameters in 2 lines instead of 1 with a seemingly random indentation:

procedure Foo(var AParameter: Integer; BParameter: Text; CParameter: Boolean;
                                                              var DParameter: DateTime) ReturnValue: Text;
var
    LocalVariable: Text;
begin
end;

Here's a screenshot from one of the countless times me (and others in my company) have had their parameters look like after hitting save, sometimes ending up in pull requests: image

These aren't intentional changes and this formatting style doesn't seem to have any clear logic to it.

5. Versions:

Final Checklist

Please remember to do the following: