Community
Participate
Working Groups
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.
It would most likely require a dedicated extension point to associate folding strategies with content types.
@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
@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.
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.
@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
@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.
> 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
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.
*** Bug 70617 has been marked as a duplicate of this bug. ***
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.
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.
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!