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

[folding] language-aware folding #3422

Closed
aeschli opened this issue Feb 24, 2016 · 105 comments
Closed

[folding] language-aware folding #3422

aeschli opened this issue Feb 24, 2016 · 105 comments
Assignees
Labels
editor-folding Editor code folding issues feature-request Request for new features or functionality
Milestone

Comments

@aeschli
Copy link
Contributor

aeschli commented Feb 24, 2016

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:

@aeschli aeschli added the editor-folding Editor code folding issues label Feb 24, 2016
@aeschli aeschli added this to the Backlog milestone Feb 24, 2016
@aeschli aeschli self-assigned this Feb 24, 2016
@aeschli aeschli changed the title [folding] provide language agnostic folding [folding] language agnostic folding Feb 24, 2016
@rkeithhill
Copy link

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.

@Tyriar Tyriar changed the title [folding] language agnostic folding [folding] language-aware folding Mar 1, 2016
@fromthewoods
Copy link

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
Copy link

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

@bgelens
Copy link

bgelens commented Mar 4, 2016

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.

@rkeithhill
Copy link

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.

@daviwil
Copy link
Contributor

daviwil commented Mar 5, 2016

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.

@aeschli
Copy link
Contributor Author

aeschli commented Mar 7, 2016

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

@jgeorgeson
Copy link

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>

@felixfbecker
Copy link
Contributor

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

@nfloersch
Copy link

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.

@pcgeek86
Copy link

Definitely need this resolved for PowerShell

@LeThiHyVong
Copy link

LeThiHyVong commented Mar 2, 2018

Atom's code folding based on indentation. But the next release (1.25) new parsing system Tree-sitter is added. I tried roughly and it's ok on small files.
May VSCode follow?
atom/atom#16299

Update: Seem like VSCode team plan to work on their own https://code.visualstudio.com/updates/v1_21#_folding

@rcjsuen
Copy link
Contributor

rcjsuen commented Mar 9, 2018

I saw that a new experimental API was introduced in VS Code 1.21. Thank you for looking into this.

Are there any plans to give control as to which line is shown after the content is folded? For example, in VS Code, the source files look like this at the top:

/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

Current folding behaviour:

/*--------------------------------------------------------------------------------------------- ...

Proposed folding behaviour:

...  *  Copyright (c) Microsoft Corporation. All rights reserved. ...
export interface FoldingRange {

	/**
	 * The start line number
	 */
	startLine: number;

	/**
	 * The end line number
	 */
	endLine: number;

	/**
	 * The line to show when the region is folded. If this is
	 * unspecified, then startLine will be shown.
	 */
	visibleLine?: number;

	/**
	 * The actual color value for this folding range.
	 */
	type?: FoldingRangeType | string;
}

@unional
Copy link

unional commented Mar 10, 2018

@rcjsuen your request is similar to #19912

@rcjsuen
Copy link
Contributor

rcjsuen commented Mar 10, 2018

Thank you for the info, @unional.

I also found #31966.

@pr-yemibedu
Copy link
Contributor

Hello,
There would need to be a really strong formatter to shrink the excessive parts of the comments to get at such useful information. That may not be the exact case now, but I wanted to brain dump it. Most typical, lines with at least one letter or number is a high candidate for keeping to favor that useful preview style. It would handle most scenarios. Thank you. Good day.

@SunOfHomeBoy
Copy link

like this

22

code fold logic have a question

@aeschli
Copy link
Contributor Author

aeschli commented Apr 10, 2018

@SunOfHomeBoy Please file a separate issue with the VSCode version and the sample code.

@beachdweller
Copy link

beachdweller commented Apr 11, 2018

Dear all,

I think I have not seen this example here yet. (Please let me know if other post discussed this already)

folding

@pr-yemibedu
Copy link
Contributor

Hello,
@Autodrive , It not a new notion to the old problem of only having indentation as the folding signal. There is now experimental syntax support possible in the mainline. It needs extension author help for the vast languages out there. Only HTML, JSON, Markdown, CSS, LESS and SCSS come available out of the box. So hopefully there can be a resolution to many of these scenarios issues. Thank you. Good day.

@aeschli
Copy link
Contributor Author

aeschli commented Apr 18, 2018

Thanks @pr-yemibedu, correct.
In the coming release language extension authors now can provide folding range providers that are based on the language syntax. Please file issues against your favourite language extension provider to add support for your language.

@paul-xtr
Copy link

paul-xtr commented May 4, 2018

The cold foldering section of the interactive playground still says that code folding is based on indentation and doesn't mention the new language aware folding. It probably should be reworded.

@Thaina
Copy link

Thaina commented May 4, 2018

Seem like it's could be done as extension now

https://code.visualstudio.com/updates/v1_23#_folding-provider-api

@peon501
Copy link

peon501 commented May 14, 2018

Any news on
image
Iam w8ting for months #37494

@aeschli
Copy link
Contributor Author

aeschli commented May 14, 2018

So the API is now available, so language extensions can add language aware folding. I reopened #37494 to continue the discussion.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
editor-folding Editor code folding issues feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests