[folding] language-aware folding
The current implementation of folding uses an indentation based folding strategy that is unaware of the language it works on. Knowledge on the underlying language allows us to solve the following requests:
- [folding] Cannot code fold empty functions #3349
- [folding] Collapse ending brace to the same line #3352
- [folding] Folded block comments should show */ #3350
- [folding] should not fold whitespace after function #3353
- [folding] Add code folding for markdown based on heading level #3347
- [folding] [lua] Weird code folding with Lua #3602
- [folding] Collapse code block ignore comments inside this block #3957
- [folding] Code Folding: support golang multiline strings #5994
- [folding] Optionally fold chained method calls #6991
Another issue I don't see in that list is user-configured folding like this example from C#:
#region Public methods
...
#endregion
In the PowerShell extension we would like to provide this same sort of feature the same syntax as what C# uses which, in PowerShell, looks like a "special" comment.
PowerShell block comment folding is weird in the Insider build 0.10.10. <# Comments here and here #> Broken: http://i.imgur.com/M6Ay1vl.gif It should fold around the <# + #> Like this: http://i.imgur.com/HFRHJJL.gif https://blogs.msdn.microsoft.com/powershell/2008/06/14/block-comments-in-v2/
Now I understand. It's the indentation level. Language-aware folding ftw!
PowerShell here-string breaks folding logic.
Here-string end marker must be placed on first column of new line.
As you can see, the function isn't folded correctly anymore although folding was done on the function keyword. Code after the here-string stays visible as well.
Yeah, I think for VSCode to give the best experience for code-folding they're definitely going to need help from the various language extensions/services.
Either that or we're going to have to tweak the PowerShell syntax definition to jive with their folding model a little better. May need some pointers from Martin about what we can do to improve folding if the tmLanguage definition is a factor.
@rkeithhill For the moment there's nothing you can tweek on your side until we allow languages to control code folding.
As another example, Ant build.xml files can have large text blocks where the content doesn't adhere to indentation of the XML. Such as
<echo file="myfle.txt">
totally unindented
text
goes here
and breaks VS Code folding
</echo>
PowerShell here-string breaks folding logic. Here-string end marker must be placed on first column of new line.
the same thing happens with PHP heredoc.
Also, sections in INI files cannot get folded by indentation
I'm probably way out of my depth here...
User-controlled folding - with "regions" - seems fairly straight-forward to define. The editor needs to only be language aware enough to know how each language shows comments. Then if a comment starts with "region" or "endregion" such as...
#region ... #endregion //region ... //endregion /region/ ... /endregion/ 'region ... 'endregion ---region ... ---endregion
...You treat the content in-between as a region. It seems like creating a list of all supported language comment syntaxes is the only thing necessary.
Definitely need this resolved for PowerShell
The language syntax files already have foldingStartMarker/foldingStopMarker. It seems that one way forward would be to use these, if available, then fall back to the current/default behavior of indentation-based folding.
Any update on this? I really need regions and here strings collapsable in PowerShell.
Any update ? Python code folding is really annoying me
Is fixing this currently on the roadmap? When can we expect this to be implemented? This is the only major blocker keeping me from using VS Code.
Adding myself here as I'd like to get proper #region..#endregion folding working for C#.
Just a suggestion - if ever you use language-aware folding, please leave indentation-based folding available as an option.
Too many editors have burned me with their intepretation of what counts as a block or not (try a mixed-language source file) and in some cases indentation is really the only way to hint source file structure.
For C#, #region and #endregion support, along with support for the recommended documentation tags, is a must before my team can use VSCode. https://msdn.microsoft.com/en-us/library/5ast78ax.aspx
@aeschli any updates on this, it's almost one year since the issue is opened?
There is currently nothing in the works, but the issue is discussed on every planning meeting and weighted against other open issues.