Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Region folding #46

Open
lwang2016 opened this issue Jun 22, 2020 · 22 comments
Open

Region folding #46

lwang2016 opened this issue Jun 22, 2020 · 22 comments
Labels
enhancement New feature or request syntax Related to language syntax

Comments

@lwang2016
Copy link
Member

Fold regions with matching # pairs, such as #parameters, or #variables.
Regions can be nested, but can't be partially overlapping. Language server should be able to calculate lines to fold/unfold.

@majastrz
Copy link
Member

Should we do it more like C# where there's a #region parameters and a corresponding #endregion declaration below? Otherwise, it's hard to tell if a region is starting or ending when you're in the middle of a big file and see #parameters.

C# regions docs

@majastrz majastrz added the syntax Related to language syntax label Jun 22, 2020
@lwang2016
Copy link
Member Author

lwang2016 commented Jun 22, 2020

Makes sense. How about
<# parameters for region start and
#>parameters for region end?

Looking for a pattern with least typing. 😆

Btw, I am totally fine with C# style.

@majastrz
Copy link
Member

That's interesting because the problem in C# is that you can't tell which region is ending and the above syntax fixes that.

@snarkywolverine
Copy link

Re: Lei's suggestion -- having 'parameters' inside at the beginning, but outside at the end... bothers me from a visual perspective.

Moving it inside ( parameters #>) fixes that.

From an authoring perspective, should we require the user to know what they're closing, and throw errors if there's a mismatch? I'm wondering how much harder this makes authoring - especially if people are adding them after the template is authored.

@majastrz
Copy link
Member

If regions are mismatched, there should be an error. (The error would be recoverable and would not interfere with authoring of a bicep file anywhere else.

It's a good question on the closing tag. C# took the approach of not requiring the name on #endregion. It solves the authoring problem, but makes it harder to figure out which region you're in. One solution for that problem could be putting regions in the symbol table, so they appear in outline and breadcrumbs. Then, just by having the cursor within a region, you would know which region you are in. (This is already working for parameters in the VS code extension.)

@abrignola
Copy link

any update on this?

@alex-frankel
Copy link
Collaborator

No update - not something we will be able to prioritize anytime soon

@dciborow
Copy link
Collaborator

dciborow commented Sep 7, 2021

I have figured out how to do this using tabs and comments in VSCode.
image

image

I seem to have no issue with running compile, but the autoformatter will snap everything back.

Would it be possible to consider an experimental setting where the autoformatter does not strip the appending \t to enable sections?

@alex-frankel
Copy link
Collaborator

Do you happen to know if there is a spec or something that VS code is implementing to be able to fold comments like this? If it's not official and just happens to work, I'd rather focus on a more reliable region folding system.

@slavizh
Copy link
Contributor

slavizh commented Sep 9, 2021

@alex-frankel may be look at the PS extension https://github.com/PowerShell/vscode-powershell. They have comments folding. Also might be good to have something like #region and #endregion like in PS. I think I had logged something like that.

@anthony-c-martin
Copy link
Member

The folding that Bicep currently supports is pretty basic, and configured via https://github.com/Azure/bicep/blob/main/src/vscode-bicep/language-configuration.json. The behavior that @dciborow is seeing with indented statements following multiline comments is definitely not intentional, and I'm assuming coming from a misconfiguration in this file, or due to some inbuilt VSCode behavior.

It's possible to get more advanced by supporting https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_foldingRange - we don't do this currently. I agree with @alex-frankel - we should come up with a design for how we want this to work, and then implement it properly; so that it's robust against e.g. autoformatting.

@yobyot
Copy link

yobyot commented Nov 22, 2021

I "get it" that there's lots to do in the language. But I think this is more important than some on the product team may think. It's what the developer sees when writing Bicep that's so important -- and so much of an improvement over bare ARM template coding.

Since Bicep is all about developer productivity and folding is basic, I would hope something could be done soon (it's almost a year between this request and the closed up request) to implement at least some basic folding.

@alex-frankel
Copy link
Collaborator

Unfortunately, the "time open" does not factor into our prioritization and while this does have some upvotes, it does not have as many as a lot of other issues in our backlog. It would be great if someone wanted to pick this up in a PR (providing an implementation proposal via this issue first), but this is not likely something the core engineering team will be able to pick up soon.

@JustinGrote
Copy link

JustinGrote commented May 13, 2022

Workaround for Visual Studio Code

Use this extension
https://marketplace.visualstudio.com/items?itemName=maptz.regionfolder

with this config:

"maptz.regionfolder": {
    "[bicep]": {
        "foldStart": "//region [NAME]",
        "foldStartRegex": "//region[\\s]*(.*)",
        "foldEnd": "//endregion",
        "foldEndRegex": "//endregion",
    }
  },

Capture

Put the extension in your workspace recommendations and the config in your workspace config to enable it for all consumers of your bicep repository in vscode.

@slavizh
Copy link
Contributor

slavizh commented May 16, 2022

@JustinGrote good workaround but there are some issues with it:

  • If it is not official it is hard to use it in code within company as everyone has to configure this
  • seems to work only (from giphy) if you do not have empty lines in your code.

@JustinGrote
Copy link

JustinGrote commented May 16, 2022

  • If it is not official it is hard to use it in code within company as everyone has to configure this

As mentioned, put it in the workspace recommendations and settings, then everyone who opens your project will have it.

  • seems to work only (from giphy) if you do not have empty lines in your code.

Works fine for me
image

@artisticcheese
Copy link

This extension messing up folding of bicep resources

Code_SIIcYWWnEm

image

@johnlokerse
Copy link
Contributor

+1 for this collapse/folding feature! I am currently building a Platform Landing Zone using Azure Bicep. The main file has loads of parameters and my Bicepparam file holds around ~1100 lines of code. This feature would be helpful to make the parameter file a bit more clean and readable.

@alex-frankel
Copy link
Collaborator

Including @johnlokerse's discussion on twitter/X as well :)

https://twitter.com/JohnLokerse/status/1780812708452925621

@kilasuit
Copy link

Should we do it more like C# where there's a #region parameters and a corresponding #endregion declaration below? Otherwise, it's hard to tell if a region is starting or ending when you're in the middle of a big file and see #parameters.

This is also how it is in PowerShell so would be my preference for implementation too especially I use regions with the outline section in VS Code for being able to navigate large files (even if I prefer working with smaller ones)

@slavizh
Copy link
Contributor

slavizh commented Apr 22, 2024

Finally more people are writing more complex code and seeing the need for this feature.

@msc365admin
Copy link

I prefer to use the #region parameter and #endregion declaration. It is widely used by C# and PowerShell developers. I already use it in my Bicep files, which will help me auto-generate segmented documentation later. For what it's worth, I've created a bicep code snippet for VS Code to start a new Bicep file.

{
    "bicep-baseline-module": {
        "scope": "bicep",
        "prefix": "bicep-baseline-module",
        "description": "",
        "body": [
            "metadata name = ''",
            "metadata description = ''",
            "metadata owner = 'solution-engineers'",
            "",
            "targetScope = 'resourceGroup'",
            "",
            "// #region Parameters",
            "// #endregion",
            "",
            "// #region Variables",
            "// #endregion",
            "",
            "// #region Deployment",
            "// #endregion",
            "",
            "// #region Definitions",
            "// #endregion",
            "",
            "// #region Output",
            "// #endregion",
        ]
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request syntax Related to language syntax
Projects
Status: Todo
Development

No branches or pull requests