AL icon indicating copy to clipboard operation
AL copied to clipboard

'#pragma warning' is not indented and hinders expand/collapse

Open TeusV opened this issue 3 years ago • 3 comments

Describe the bug When saving an al file, lines starting with '#pragma warning' are not indented. If you did indent, the indent is removed. Then when expanding/collapsing a code block (such as layout{}), the collapse stops at the '#pragma warning' line. Indentation equal to that of comments would make more sense.

To Reproduce

  1. On a page, in the layout{} section, add a new line '#pragma warning'
  2. Save the file (indents are removed)
  3. Collapse the layout{} section
page 50000 MyPage
{
    SourceTable = "Sales Header";

    layout
    {
        area(content)
        {
            #pragma warning disable AA0218
            group(General)
            {
                field(No; Rec."No.")
                {
                    ApplicationArea = All;
                }
            }
            #pragma warning restore AA0218
        }
    }
}

Expected behavior Indents of '#pragma warning' are treated the same as indents of comments (or, worse but better than now, left alone, like some table relation indents).

Screenshots uKx1daQScw

5. Versions:

  • AL Language: 6.6.425415
  • Business Central: W1 17.4 (Platform 17.0.21485.21516 + Application 17.0.16993.0)

TeusV avatar Mar 15 '21 14:03 TeusV

This might be inspired by C/C++, where AFAIK the general convention is to keep preprocessor directives in column 0 (I think the leading # might even have to be there). But yeah, it's not ideal, especially if it interferes functionally with things like expand/collapse.

dzzzb avatar Mar 15 '21 15:03 dzzzb

This might be inspired by C/C++, where AFAIK the general convention is to keep preprocessor directives in column 0 (I think the leading # might even have to be there). But yeah, it's not ideal, especially if it interferes functionally with things like expand/collapse.

From what I'm reading, this was also something that they reported over at the vscode/c++ tools by microsoft issue #406

But yes, I'd like to bump this issue as it's making code navigation a headache.

Ji-Peter avatar Jun 28 '22 04:06 Ji-Peter

@thloke This also impacts regions: As long as the file is not saved and the pragma is still indented, the region is foldable: image

And as soon as I save = remove the pragma indentation, the region is broken: image

NKarolak avatar Aug 08 '22 12:08 NKarolak

Hi, we have defined an AL custom code folding, which ignores processor directives as expanding and collapsing anchors. We will keep the processor directives in column 0, as per convention, but they will no longer interfere with the code navigation.

blrobl avatar Dec 13 '22 10:12 blrobl

@blrobl @JesperSchulz I tried to give this a spin with the v11.0.748446 vsix insider and got it working (I think) only once using the 'Fold Level 1' action. This showed only the field definition, function signature and [IntegrationEvent(false, false)] as lines, which was (almost) perfect!

However, I can't get it working any longer. Is 'Fold Level 1' the proper action, or should we use different commands?

Until now, we are use regions to fold by region, but if we can use standard folding to only show function names without using regions, that would be great !

PS: When folding on level 1, I always get [IntegrationEvent(false, false)] for the events. Any option to show the signature instead?

image

UPDATE What I'm trying to achieve is to get some kind of view similar to the 'AL / Code Outline', showing only fields, controls, function names, without var section / code / properties. This can provide a quick overview on how the object is designed.

'Fold Level 3' seems to provide the best result.

image

fvet avatar Feb 12 '23 19:02 fvet

I'll let someone from the compiler team answer this one :-)

JesperSchulz avatar Feb 13 '23 07:02 JesperSchulz

I'll let someone from the compiler team answer this one :-)

@JesperSchulz Any hint on who to tag to get some feedback?

fvet avatar Feb 14 '23 15:02 fvet

@blrobl - can you check the feedback above?

thloke avatar Feb 15 '23 04:02 thloke