Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Relevant issues: https://bugs.eclipse.org/bugs/show_bug.cgi?id=173796 (and there are also similar ones like https://bugs.eclipse.org/bugs/show_bug.cgi?id=258965 for CDT)
What it does
This PR allows to add custom folding regions using comments.
I added new options to the preferences in
Java
>Editor
>Folding
(not that I changed this preference page to useGroup
s):If a comment containing the start region and a comment containing the end region are present in the same source file, a folding region is added allowing to collapse that section.
This works even for elements of different levels, e.g.
Notes / What I'm not sure about
Custom folding regions are disabled if either of the custom texts/preferences are empty or if one contains the other. Should I add some information about that to the preferences? Would it be better to disable it by default (currently, it defaults to
#region
/#endregion
)?I haven't written any tests so far. Are there existing tests for folding in JDT-UI? What about performance tests (my implementation requires scanning more parts of the source file which could affect performance)?
Regarding performance, I used
String#contains
to check whether comments contain certain the region begin/end tokens (e.g.#region
/#endregion
) which requires creating aString
for each comment every time the file is edited. Should I change that to use thechar[]
returned bygetCurrentTokenSource()
or similar?I have bumped the minor version of
org.eclipse.jdt.ui
due to adding new elements inPreferenceConstants
. Is this ok that way?I guess this should be added to the "New and noteworthy" list (assuming this change gets accepted and merged). If so, should I add it and is this the right place?
How to test
#region
#endregion
Java
>Editor
>Folding
, it is necessary to reopen the source file.Author checklist