Bug 512956 - [generic editor] Code folding for generic editor
Summary: [generic editor] Code folding for generic editor
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 4.7   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 4.8 M1   Edit
Assignee: Lucas Bullen CLA
QA Contact:
URL:
Whiteboard:
Keywords: Documentation, noteworthy
: 70617 (view as bug list)
Depends on: 508829
Blocks:
  Show dependency tree
 
Reported: 2017-03-02 08:01 EST by Alexander Kurtakov CLA
Modified: 2017-07-20 11:30 EDT (History)
6 users (show)

See Also:


Attachments
Folding Indent strategy (228.29 KB, image/gif)
2017-03-08 17:30 EST, Angelo ZERR CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Kurtakov CLA 2017-03-02 08:01:41 EST
Code folding would require addition of a folding strategy that languages should contribute to generic editor via extension points, as folding rules are language specific. 
Let's discuss the path forward here.
Comment 1 Mickael Istria CLA 2017-03-06 04:31:00 EST
It would most likely require a dedicated extension point to associate folding strategies with content types.
Comment 2 Angelo ZERR CLA 2017-03-06 04:37:45 EST
@Mickael,

I have developped a generic folding strategy (VSCode like) inside typescript.java which folds editor content by using indents at https://github.com/angelozerr/typescript.java/blob/master/eclipse/ts.eclipse.ide.ui/src/ts/eclipse/ide/ui/folding/IndentFoldingStrategy.java

In my case, I have extended this class for TypeScript at https://github.com/angelozerr/typescript.java/blob/master/eclipse/jsdt/ts.eclipse.ide.jsdt.ui/src/ts/eclipse/ide/jsdt/internal/ui/editor/TypeScriptFoldingStrategy.java to fold content for "import" block.

You could provide this folding strategy by default. Tell me, if you are interested.

Regard's Angelo
Comment 3 Mickael Istria CLA 2017-03-06 05:06:36 EST
@Angelo: thanks, we'll for sure look at it. However, the main example we have in mind at the moment is folding the license header, and a whitespace-based strategy would work for it.
TBH, I don't think folding is very important as the IDE offers a lot of very efficient way to read and navigate in code without folding. The only case of folding I'd find necessary are the default ones in JDT: fold license, fold import... because they hide useless stuff as I'm reading and prevents from scrolling everytime I open a new file.
Comment 4 Angelo ZERR CLA 2017-03-08 17:30:34 EST
Created attachment 267180 [details]
Folding Indent strategy

@Mickael here a demo with my Folding Indent Strategy. You can see that LICENSE header is folded because it is indented.
Comment 5 Angelo ZERR CLA 2017-03-08 17:35:41 EST
@Mickael, just for your information, Textmate can defines folding in their grammar. I have created this issue at https://github.com/eclipse/tm4e/issues/50
Comment 6 Mickael Istria CLA 2017-03-09 03:18:43 EST
@Angelo: ok thanks. Then we'll probably add such a whitespace-based folding strategy as default in the generic editor, and let extenders plug-in alternative strategies for specific content-types.
Actually, if this happens to work well, we could consider adding the whitespace folding strategy in M7 (without letting people override it) and create the extension point for Photon.M1.
I'm putting a tentative target to M7 to add such as strategy.
Comment 7 Angelo ZERR CLA 2017-03-09 03:23:35 EST
> Then we'll probably add such a whitespace-based folding strategy as default in the generic editor,

Very cool!

I think my folding strategy works well but it should be improved perhaps because it folds the whole content of the editor. But performance are very good without this optimization.

IMHO, I think Platform Text should provide this generic indent folding strategy. It exists a bug for that at https://bugs.eclipse.org/bugs/show_bug.cgi?id=70617
Comment 8 Mickael Istria CLA 2017-03-22 12:32:33 EDT
Some discussion with adopters of generic editor has lead to the conclusion that a default whitespace-based folding is not very useful and doesn't deserve high priority.
It still appears that language specific strategies are necessary (for example to folder copyright header or imports in Java), and so far, that requires too much effort and change to be do-able in 4.7. So moving this to 4.8.
Comment 9 Dani Megert CLA 2017-03-22 12:33:42 EDT
*** Bug 70617 has been marked as a duplicate of this bug. ***
Comment 10 Mickael Istria CLA 2017-07-06 16:12:30 EDT
The frustrating part with this work is that at the moment, there is no good existing interface that is specific to adding a folding strategy: it basically takes a generic reconcilier, and adopter has to care about using viewer.getProjectionAnnotationModel() to add specific ProjectionAnnotations. There seems to be no dedicated interface or abstract class for that.

So if we want to make migration easy from legacy to Generic Editor (and we do!) I think we have to provide a generic extension point for generic reconcilers anyway and document in the extension point and show in example and PDE template that this extension point is the one to use to deal with folding.
Comment 11 Mickael Istria CLA 2017-07-18 11:04:23 EDT
This is covered by the same patch as reconciler: https://git.eclipse.org/r/#/c/101429/
But that should be documented in the official doc that reconcilers can be used for foldings, in the N&N and in the PDE Template.
Comment 12 Mickael Istria CLA 2017-07-20 11:30:47 EDT
Fixed with http://git.eclipse.org/c/platform/eclipse.platform.text.git/commit/?id=798ba99e71d97835741ac91d068afc2130c66bcc

Let's mark this bug as resolved, and keep bug 508829 to track progress for documentation, New & Noteworthy page and PDE Template, as folding is the example use case for a reconciler.

Thanks a lot to Lucas for this very good contribution!