bicep
bicep copied to clipboard
Region folding
Fold regions with matching #
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
.
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.
That's interesting because the problem in C# is that you can't tell which region is ending and the above syntax fixes that.
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.
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.)
any update on this?
No update - not something we will be able to prioritize anytime soon
I have figured out how to do this using tabs and comments in VSCode.
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?
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.
@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.
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.
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.
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.
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",
}
},
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.
@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.
- 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
This extension messing up folding of bicep resources
+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.
Including @johnlokerse's discussion on twitter/X as well :)
https://twitter.com/JohnLokerse/status/1780812708452925621
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)
Finally more people are writing more complex code and seeing the need for this feature.