vscode icon indicating copy to clipboard operation
vscode copied to clipboard

[folding] language-aware folding

Open aeschli opened this issue 10 years ago • 105 comments

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

aeschli avatar Feb 24 '16 15:02 aeschli

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.

rkeithhill avatar Feb 27 '16 04:02 rkeithhill

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/

fromthewoods avatar Mar 03 '16 16:03 fromthewoods

Now I understand. It's the indentation level. Language-aware folding ftw!

fromthewoods avatar Mar 03 '16 16:03 fromthewoods

PowerShell here-string breaks folding logic. Here-string end marker must be placed on first column of new line. untitled 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.

bgelens avatar Mar 04 '16 21:03 bgelens

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.

rkeithhill avatar Mar 04 '16 22:03 rkeithhill

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.

daviwil avatar Mar 05 '16 02:03 daviwil

@rkeithhill For the moment there's nothing you can tweek on your side until we allow languages to control code folding.

aeschli avatar Mar 07 '16 09:03 aeschli

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>

jgeorgeson avatar Mar 09 '16 17:03 jgeorgeson

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

felixfbecker avatar Mar 12 '16 10:03 felixfbecker

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.

nfloersch avatar Mar 16 '16 14:03 nfloersch

Definitely need this resolved for PowerShell

pcgeek86 avatar Mar 30 '16 18:03 pcgeek86

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.

Seairth avatar Jun 08 '16 14:06 Seairth

Any update on this? I really need regions and here strings collapsable in PowerShell.

adbertram avatar Nov 18 '16 13:11 adbertram

Any update ? Python code folding is really annoying me

DollarAkshay avatar Dec 28 '16 09:12 DollarAkshay

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.

Sevin777 avatar Jan 05 '17 14:01 Sevin777

Adding myself here as I'd like to get proper #region..#endregion folding working for C#.

DustinCampbell avatar Jan 07 '17 20:01 DustinCampbell

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.

madumlao avatar Jan 09 '17 05:01 madumlao

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

hlink avatar Jan 20 '17 07:01 hlink

@aeschli any updates on this, it's almost one year since the issue is opened?

Huachao avatar Feb 26 '17 09:02 Huachao

There is currently nothing in the works, but the issue is discussed on every planning meeting and weighted against other open issues.

aeschli avatar Feb 27 '17 09:02 aeschli