anzwdev / al-code-outline

AL Code Outline for Visual Studio Code
MIT License
51 stars 13 forks source link

Add tooltips command does not preserve separating line between properties and triggers #563

Closed ernestasjuska closed 3 months ago

ernestasjuska commented 5 months ago

Hi,

Add tooltips command does not preserve separating line between properties and triggers

Before:

            action(Open)
            {
                ApplicationArea = S4Leasing;
                Caption = '&Open';
                Image = Document;
                Promoted = true;
                PromotedCategory = New;
                PromotedIsBig = true;
                ShortcutKey = 'F9';

                trigger OnAction()
                begin
                    CreateOpenDocument;
                end;
            }

After:

            action(Open)
            {
                ApplicationArea = S4Leasing;
                Caption = '&Open';
                Image = Document;
                Promoted = true;
                PromotedCategory = New;
                PromotedIsBig = true;
                ShortcutKey = 'F9';
                ToolTip = 'Executes the &Open action.';
                trigger OnAction()
                begin
                    CreateOpenDocument;
                end;
            }

Expected:

            action(Open)
            {
                ApplicationArea = S4Leasing;
                Caption = '&Open';
                Image = Document;
                Promoted = true;
                PromotedCategory = New;
                PromotedIsBig = true;
                ShortcutKey = 'F9';
                ToolTip = 'Executes the &Open action.';

                trigger OnAction()
                begin
                    CreateOpenDocument;
                end;
            }

I think the command should work like this:

  1. start after opening {;
  2. find the last property and if one does not exist go to step 4;
  3. skip block comments + optional line comment that follow the last property closing ; on the same line;
  4. write a line break;
  5. write the tooltip property.

Personally, I like to have all "translatable" properties at the beginning of the property list, so Caption, CaptionClass, ShowCaption, ToolTip, OptionCaption, etc. Step 2 could be adapted to only search Caption/CaptionClass/ShowCaption properties and if they don't exist to add ToolTip property at the beginning of the propertly list.

Thanks.

Examples (existing line break is <ELB> and added line break is ALB):

// before:
{<ELB>
}

// after:
{<ALB>
    ToolTip = '...';<ELB>
}
// before:
{<ELB>

    trigger OnValidate()
    begin
    end;
}

// after:
{<ALB>
    ToolTip = '...';<ELB>

    trigger OnValidate()
    begin
    end;
}
// before:
{
    Caption = 'ABC';<ELB>

    trigger OnValidate()
    begin
    end;
}

// after:
{
    Caption = 'ABC';<ALB>
    ToolTip = '...';<ELB>

    trigger OnValidate()
    begin
    end;
}

I don't think this command should correct code layout in this case. There should be other command for that.

// before:
{
    Caption = 'ABC';<ELB>
    trigger OnValidate()
    begin
    end;
}

// after:
{
    Caption = 'ABC';<ALB>
    ToolTip = '...';<ELB>
    trigger OnValidate()
    begin
    end;
}

Block comments and optional line comments "extend" the current line so long as next comments does not start in its own line:

// before:
{
    Caption = 'ABC'; /* A
                                   B
                                   C
                                */ /*
                                   D
                                   E
                                   F */ /// bla bla <ELB>
    // assuming that this line comments comments things after it

    trigger OnValidate()
    begin
    end;
}

// after:
{
    Caption = 'ABC'; /* A
                                   B
                                   C
                                */ /*
                                   D
                                   E
                                   F */ /// bla bla  <ALB>
    Tooltip = '...';<ELB>
    // assuming that this line comments comments things after it

    trigger OnValidate()
    begin
    end;
}
anzwdev commented 3 months ago

Thank you for reporting the issue, it has been fixed in the last release.