AL icon indicating copy to clipboard operation
AL copied to clipboard

Autoformat tends to spread parameters into 2 lines on save

Open bjarkihall opened this issue 1 month ago • 0 comments

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:

  • AL Language: v14.0.1055126 (pre-release), but it's also been this way since runtime 11 and before
  • Visual Studio Code: 1.90.2, but I think it's been like this since interfaces were introduced
  • Business Central: 24.1
  • List of Visual Studio Code extensions that you have installed: AL Language Extension, others are disabled

Final Checklist

Please remember to do the following:

  • [x] Search the issue repository to ensure you are reporting a new issue

  • [x] Reproduce the issue after disabling all extensions except the AL Language extension

  • [x] Simplify your code around the issue to better isolate the problem

bjarkihall avatar Jun 28 '24 12:06 bjarkihall