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
730 stars 243 forks source link

regions in AL #1007

Closed RafaelKoch closed 3 years ago

RafaelKoch commented 6 years ago

just a quick question: is there a way to use regions in AL? So something like

#region Write Log to File 
many many lines of code you would like to conveniently collapse
#endregion
thpeder commented 6 years ago

AL doesn't have support for regions at this moment. We have a general issue with adding code folding to the Visual Studios Code extension because of lack of support: https://github.com/Microsoft/vscode/issues/3422

yrest commented 6 years ago

@thpeder , Is it possible or are there any plans to make AL extension for VS Code available on "full visual studio" marketplace?

StanislawStempin commented 6 years ago

We do not have any plans to support full Visual Studio. Please see #932 for more details.

anzwdev commented 6 years ago

I've just manually added this section to al.configuration.json file in al extension folder:

"folding": {
        "markers": {
            "start": "^\\s*//\\s*#region\\b",
            "end": "^\\s*//\\s*#endregion\\b"
        }
    }

and I can use //#region and //#endregion in al files as in the attached picture now:

regions

Could you include this modification in AL extension?

anzwdev commented 6 years ago

I've also modified alsyntax.tmlanguage file to get better region colors by adding this based on c# language definition part:

        <dict>
            <key>begin</key>
            <string>(^\s*)?(?=//\s*#region\b)</string>
            <key>beginCaptures</key>
            <dict>
                <key>1</key>
                <dict>
                    <key>name</key>
                    <string>keyword.preprocessor.region.al</string>
                </dict>
            </dict>
            <key>end</key>
            <string>(?!\G)</string>
            <key>patterns</key>
            <array>
                <dict>
                    <key>begin</key>
                    <string>//\s*#region</string>
                    <key>beginCaptures</key>
                    <dict>
                        <key>0</key>
                        <dict>
                            <key>name</key>
                            <string>keyword.preprocessor.region.al</string>
                        </dict>
                    </dict>
                    <key>end</key>
                    <string>\n</string>
                    <key>name</key>
                    <string>string.unquoted.preprocessor.message.al</string>
                </dict>
            </array>
        </dict>

        <dict>
            <key>match</key>
            <string>^\s*//\s*#endregion\b</string>
            <key>name</key>
            <string>keyword.preprocessor.region.al</string>
        </dict>

and it looks much better now:

regions2

Gallimathias commented 6 years ago

It would be even nicer if the two of them // would fall away and only # should be use. A region is not a comment. In addition, a different color than blue would be good e. g. grey as it is not a command statement.

thpeder commented 6 years ago

Thanks the both of you for your suggestions. It is on our backlog but we are discussion internally how we want this to look.

anzwdev commented 6 years ago

I am trying to find a solution that won't require any changes to AL compiler and //#region and //#endregion tags seem to be better as they are already used for regions definition in javascript files in Visual Studio Code:

jsregion

You can see that they have been defined by VS Code team at the end of this file: https://github.com/Microsoft/vscode/blob/master/extensions/javascript/javascript-language-configuration.json

I agree with you, it might be good to use different color for region/endregion tags but in my example I was again trying to use something that has already been defined by VS Code team and I've decided to copy color settings from C# language definition from this file: https://github.com/Microsoft/vscode/blob/master/extensions/csharp/syntaxes/csharp.tmLanguage.json

As you can see, VS Code team decided to use:

And that's how VS Code shows region for C# files: regionscs

anzwdev commented 6 years ago

Thank you @thpeder

jimmymcp commented 6 years ago

My two cents to add to this thread,

I use the options to collapse and expand some/all functions in the dev environment all the time. I'd love to be able to do the same thing in VS Code - and preferably without having to define regions for each function - but I'm open to how you think to best implement this sort of thing.

BartPermentier commented 6 years ago

I got tired of manually adding the example code of anzwdev to AL every update so I created an extension that does it automatically. https://marketplace.visualstudio.com/items?itemName=BartPermentier.al-toolbox

NKarolak commented 3 years ago

The regions directive has been released with BC 17 https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/directives/devenv-directive-region

RafaelKoch commented 3 years ago

Oh splendid :-) Thanks @NKarolak for pointing this out here. I will close this evergreen feature request then :-)

I also love the code example... image