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

add custom folding regions #1825

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

danthe1st
Copy link

@danthe1st danthe1st commented Dec 2, 2024

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 use Groups):
folding preference dialog including custom folding regions

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.

non-collapsed custom region
collapsed custom region
hovering over collapsed region indicator showing content

This works even for elements of different levels, e.g.

// #region
void a(){
    // #endregion
}

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 a String for each comment every time the file is edited. Should I change that to use the char[] returned by getCurrentTokenSource() or similar?

I have bumped the minor version of org.eclipse.jdt.ui due to adding new elements in PreferenceConstants. 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

  • Create a Java source file
  • Create a comment containing the text #region
  • Create a comment containing the text #endregion
  • Test similar things with the source file
  • After editing the corresponding changes in Java > Editor > Folding, it is necessary to reopen the source file.

Author checklist

@danthe1st danthe1st force-pushed the folding branch 2 times, most recently from 0301e82 to 1828731 Compare December 4, 2024 22:01
@danthe1st danthe1st marked this pull request as ready for review December 4, 2024 22:05
@danthe1st danthe1st force-pushed the folding branch 2 times, most recently from 79d16c0 to 56d6c84 Compare December 5, 2024 10:41
@HannesWell
Copy link
Contributor

@fedejeanne in the dev-call on Thursday you mentioned that you could have a look at this, does this still stand?
Eventueally we need a JDT committer to submit this anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants