Skip to content

Conversation

@danthe1st
Copy link
Contributor

@danthe1st danthe1st commented Jun 29, 2025

This is my attempt to fix #3073 in order to implement eclipse-jdt/eclipse.jdt.ui#2264

Description

ProjectionViewer currently cannot use visible regions and projections together (except by calling enableProjections() after setVisibleRegions in which case it will show a wrong region). This PR changes the implementation of visible regions to collapse everything outside the visible region.

Note

This PR does not allow collapsing or expanding any projection/folding regions outside of the declared visible region (e.g. by other code modifying the document in some way or if a projection region is partially in the visible region).

Aside from that, this implementation has the following effect: If setVisibleRegion is called with a region that is fully collapsed, the editor is basically empty. If another behavior is desired, it would be good to know what the better behavior is.

testing with JDT

To test this with JDT as requested in eclipse-jdt/eclipse.jdt.ui#2264, do the following:

  • Create a workspace with eclipse.platform.ui and JDT-UI set up (I did so by creating a Target Platform and added whatever I thought was necessary until I no longer got any errors but I have no idea how to properly do that)
  • Use the changes in eclipse.platform.ui
  • Apply enable folding with "Only show selected Java element" eclipse-jdt/eclipse.jdt.ui#2302 with JDT-UI:
  • Create an "Eclipse Application" run configuration with this version of Eclipse Platform and the patched version of JDT-UI and start it
  • Enable Window > Preferences > Java > Editor > "Only show the selected Java Element"
  • Make sure folding is enabled at Window > Preferences > Java > Editor > Folding
  • Open a Java class
  • Select elements in the outline and observe that only the "selected element" is shown in the editor and folding still works (whether it's normal folding, custom folding regions, "Extended Folding", etc shouldn't make a difference)
    image
  • If "Enhanced Folding" is active, make sure that preserve contextual information with enhanced folding eclipse-jdt/eclipse.jdt.ui#2410 is available as well

@github-actions
Copy link
Contributor

github-actions bot commented Jul 3, 2025

Test Results

 2 778 files  ± 0   2 778 suites  ±0   1h 36m 42s ⏱️ - 7m 29s
 7 943 tests +11   7 714 ✅ +11  228 💤 ±0  1 ❌ ±0 
23 384 runs  +33  22 637 ✅ +33  746 💤 ±0  1 ❌ ±0 

For more details on these failures, see this check.

Results for commit da38e3d. ± Comparison against base commit 477d106.

♻️ This comment has been updated with latest results.

@iloveeclipse
Copy link
Member

@danthe1st : thanks for PR, few things:

  1. Please rebase on master
  2. Please squash two commits into one
  3. Please update commit message to follow commit message guidelines: https://github.com/eclipse-platform/.github/blob/main/CONTRIBUTING.md#commit-message-recommendations

@danthe1st
Copy link
Contributor Author

danthe1st commented Jul 3, 2025

@danthe1st : thanks for PR, few things:

1. Please rebase on master

2. Please squash two commits into one

3. Please update commit message to follow commit message guidelines: https://github.com/eclipse-platform/.github/blob/main/CONTRIBUTING.md#commit-message-recommendations

I'll make sure to do that once I located and fixed a remaining issue in combination with JDT (if I select a method that's within a custom folding region and enter text, it seems to show "too much" text for some reason). While I think that's an issue with JDT-UI (it only seems to happen with custom folding regions and extended folding), I want to be sure about it first (and I opened this PR before everything is finished to make it visible in advance/allow for discussion if applicable).

@danthe1st danthe1st force-pushed the projections-with-visible-regions branch from bb4f64a to 5274f99 Compare July 5, 2025 12:48
danthe1st added a commit to danthe1st/eclipse.platform.ui that referenced this pull request Jul 5, 2025
While ProjectionViewer supports both using visible regions and
projections, these features cannot be used in conjunction. This change
allows the use of projections when visible regions are used.

Fixes eclipse-platform#3074
@danthe1st
Copy link
Contributor Author

danthe1st commented Jul 5, 2025

I have made the requested changes. However, I want to note the following:

  • This has an impact on behavior(al compatibility). If some project/plugin/whatever calls enableProjections() and setVisibleRegion on some ProjectionViewer, this PR affects what is shown to the user.
  • I didn't do performance testing.
  • I think it would be a good idea for someone from JDT (or other projects if make use of this?) to test it before this is merged.

danthe1st added a commit to danthe1st/eclipse.platform.ui that referenced this pull request Jul 5, 2025
While ProjectionViewer supports both using visible regions and
projections, these features cannot be used in conjunction. This change
allows the use of projections when visible regions are used.

Fixes eclipse-platform#3074
@danthe1st danthe1st force-pushed the projections-with-visible-regions branch from 5274f99 to 5b7cb97 Compare July 5, 2025 14:40
danthe1st added a commit to danthe1st/eclipse.platform.ui that referenced this pull request Jul 5, 2025
While ProjectionViewer supports both using visible regions and
projections, these features cannot be used in conjunction. This change
allows the use of projections when visible regions are used.

Fixes eclipse-platform#3074
@danthe1st danthe1st force-pushed the projections-with-visible-regions branch from 5b7cb97 to fb861bc Compare July 5, 2025 14:59
@danthe1st
Copy link
Contributor Author

danthe1st commented Jul 5, 2025

I am not sure why the Jenkins build seems to have issues getting tycho set up (maybe issues with https://repo.eclipse.org/?)

@merks
Copy link
Contributor

merks commented Jul 5, 2025

Yes there are infrastructure problems again:

I restarted the build.

danthe1st added a commit to danthe1st/eclipse.platform.ui that referenced this pull request Jul 5, 2025
While ProjectionViewer supports both using visible regions and
projections, these features cannot be used in conjunction. This change
allows the use of projections when visible regions are used.

Fixes eclipse-platform#3074
@danthe1st danthe1st force-pushed the projections-with-visible-regions branch from fb861bc to c5fb5f3 Compare July 5, 2025 17:24
@merks
Copy link
Contributor

merks commented Jul 5, 2025

It looks like there was a test failure:

https://ci.eclipse.org/platform/job/eclipse.platform.ui/job/PR-3074/lastCompletedBuild/testReport/

danthe1st added a commit to danthe1st/eclipse.platform.ui that referenced this pull request Jul 5, 2025
While ProjectionViewer supports both using visible regions and
projections, these features cannot be used in conjunction. This change
allows the use of projections when visible regions are used.

Fixes eclipse-platform#3074
@danthe1st danthe1st force-pushed the projections-with-visible-regions branch from c5fb5f3 to f34844d Compare July 5, 2025 18:28
danthe1st added a commit to danthe1st/eclipse.platform.ui that referenced this pull request Jul 5, 2025
While ProjectionViewer supports both using visible regions and
projections, these features cannot be used in conjunction. This change
allows the use of projections when visible regions are used.

Fixes eclipse-platform#3074
@danthe1st danthe1st force-pushed the projections-with-visible-regions branch from f34844d to 7ff50f2 Compare July 5, 2025 19:00
danthe1st added a commit to danthe1st/eclipse.platform.ui that referenced this pull request Jul 6, 2025
While ProjectionViewer supports both using visible regions and
projections, these features cannot be used in conjunction. This change
allows the use of projections when visible regions are used.

Fixes eclipse-platform#3074
@danthe1st danthe1st force-pushed the projections-with-visible-regions branch from 7ff50f2 to 2ce3ba0 Compare July 6, 2025 08:06
@danthe1st
Copy link
Contributor Author

I now switched to an approach that should have fewer side effects. Instead of adding additional projection regions, I am now using the expand() and collapse() methods directly.

danthe1st added a commit to danthe1st/eclipse.platform.ui that referenced this pull request Jul 6, 2025
While ProjectionViewer supports both using visible regions and
projections, these features cannot be used in conjunction. This change
allows the use of projections when visible regions are used.

Fixes eclipse-platform#3074
@danthe1st danthe1st force-pushed the projections-with-visible-regions branch 2 times, most recently from d2f4f5a to 7a9cf09 Compare July 6, 2025 10:51
danthe1st added a commit to danthe1st/eclipse.platform.ui that referenced this pull request Jul 6, 2025
While ProjectionViewer supports both using visible regions and
projections, these features cannot be used in conjunction. This change
allows the use of projections when visible regions are used.

Fixes eclipse-platform#3074
@iloveeclipse
Copy link
Member

This PR caused regression: #3380
@mickaelistria, @danthe1st : could you please check?

@iloveeclipse
Copy link
Member

This PR caused another regression: eclipse-jdt/eclipse.jdt.ui#2532

@mickaelistria, @danthe1st : please follow up. The way the listener is added & removed is not OK, as it will be not always removed. A simple solution is doable, I've posted it on the bug, but I'm not sure if that is enough.

@mickaelistria
Copy link
Contributor

@danthe1st @iloveeclipse I think we should give about a week for a fix to be pushed, and if nothing has happened before that, we can revert.

@cdietrich
Copy link
Contributor

cdietrich commented Oct 13, 2025

causes breaking change in Xtext comment editing strategy eclipse-xtext/xtext#3531

@totomomo18
Copy link

is this feature included in the new Eclipse 2025 12 ? where is it going to be included in a official release ?

@merks
Copy link
Contributor

merks commented Dec 10, 2025

is this feature included in the new Eclipse 2025 12 ? where is it going to be included in a official release ?

It's merged so I expect it is in the release, which will go live later today.

@totomomo18
Copy link

I can not wait :) Thanks for the replay

@danthe1st
Copy link
Contributor Author

danthe1st commented Dec 10, 2025

is this feature included in the new Eclipse 2025 12 ? where is it going to be included in a official release ?

This feature s included in 2025-12 but the JDT one as some issues are still open. See #3456 (my plan was to rebase that and test everything and some point this month/after the release but I didn't get to it) (and technically also #3457 (comment) but I don't consider that to be a big issue).

if you really want to try it out, feel free to build JDT-UI from source (if you need help with that, you can contact me directly if you want to).

@totomomo18
Copy link

Just downloaded the new Sts and I tested it it seem to be working Thank You very much :)

Why don't they include this feature in the new features I looked for it in the New & Noteworthy page
https://eclipseide.org/release/noteworthy/

For me it is an important fix which is so useful allow to use both the folding and the show only selected element together at the same time. It really help you to focus on the code you want to work at the a specific method

@danthe1st
Copy link
Contributor Author

danthe1st commented Dec 10, 2025

Just downloaded the new Sts and I tested it it seem to be working

It shouldn't do anything if you don't have the JDT-UI patch (or use a different editor making use of that) which isn't merged yet..? This is why there's no N&N about it in 2025-12.

This PR is just about giving Eclipse Platform the necessary capabilities for this. Of course, a custom editor may use that functionality.

But yes, if you apply the JDT-UI patch yourself and somehow install it into Spring Tools 5 (or Eclipse 2025-12), it should work.

@totomomo18
Copy link

totomomo18 commented Dec 10, 2025

It seem to be working but the closing bracket of the method that is show only selected element seem to disappear

Before show selected element

image

After show selected element
image

@danthe1st
Copy link
Contributor Author

danthe1st commented Dec 10, 2025

It seem to be working but the closing bracket of the method that is show only selected element seem to disappear

Oh, I think I understand why it "works" for you. This is just because you enabled the option while the file is opened. The JDT-UI change (which is not merged yet) makes sure that this feature works on newly opened files (basically, it removes some code that disables that feature). Until eclipse-jdt/eclipse.jdt.ui#2302 is merged, you cannot expect this to work. If you close and reopen the file, it shouldn't show any folding regions.
That being said, I don't know why exactly the } is hidden but I couldn't yet test it with the new version.

If a } is hidden, I might be able to check it if I have the exact code (with the exact whitespace used, including on lines containing only whitespace).

But for Java-specific things, this (platform-UI) is (probably) not the right repository.

Note: I am just an outside contributor, I am not a maintainer of any Eclipse projects. I am just occasionally contributing to Eclipse in my free time (when I consider something to be important or interesting enough).

@totomomo18
Copy link

Should I report the disappearing bracket when invoking show only selected element as bug to Eclipse or Sts Repository ?
if yes which repository ?
I know that this is a new bug since disappearing bracket did not disappear in previous eclipse/sts version

Also when do you think the patch of JDT-UI patch be merged ?
Do you think that this patch will slove the disappearing bracket problem ?

@danthe1st
Copy link
Contributor Author

danthe1st commented Dec 11, 2025

Should I report the disappearing bracket when invoking show only selected element as bug to Eclipse or Sts Repository ?
if yes which repository ?

If you can reproduce it with Eclipse 2025-12 and eclipse-jdt/eclipse.jdt.ui#2302 (you have to compile JDT-UI yourself), please add a comment in that issue (and hopefully, I can take a look). If it cannot be reproduced like that, I don't think it would be a bug as it isn't enabled anyways. Spring Tools would be the wrong repository.

Also when do you think the patch of JDT-UI patch be merged ?

Whenever it's finished. It depends on my motivation. There's also another issue with it which would be good to resolve first.

Creating a new issue for something JDT-UI specific doesn't make sense as the relevant PR isn't merged yet (again, it only affects open editors when you enable the feature in the preferences).

@totomomo18
Copy link

totomomo18 commented Dec 11, 2025

Should I report the disappearing bracket when invoking show only selected element as bug to Eclipse or Sts Repository ?
if yes which repository ?

If you can reproduce it with Eclipse 2025-12 and eclipse-jdt/eclipse.jdt.ui#2302 (you have to compile JDT-UI yourself), please add a comment in that issue (and hopefully, I can take a look). If it cannot be reproduced like that, I don't think it would be a bug as it isn't enabled anyways. Spring Tools would be the wrong repository.

Also when do you think the patch of JDT-UI patch be merged ?

Whenever it's finished. It depends on my motivation. There's also another issue with it which would be good to resolve first.

Creating a new issue for something JDT-UI specific doesn't make sense as the relevant PR isn't merged yet.

I just downloaded Eclipse 2015 12 ( not Sts basic Eclipse ide in zip format) from the website. A clean install without your patch (because I dont know how to install it or compile and ide with a patch) and did the same test the folding sort of work with show only selected element and bracket still disappear it seem to be a bug that did happen before should I report it as a bug ? and to which repository ?

Before invoking show only selected element on the main method
image

After invoking show only selected element on the main method
image

@danthe1st
Copy link
Contributor Author

danthe1st commented Dec 11, 2025

A clean install without your patch (because I dont know how to install it or compile and ide with a patch) and did the same test the folding sort of work with show only selected element and bracket still disappear it seem to be a bug that did happen before should I report it as a bug ? and to which repository ?

Does it also happen if you close and reopen the editors after setting the preference (without changing the preference again)? Also, it would be useful to know the exact code you are using (with whitespace) and the folding configuration. If not, I wouldn't consider this to be a fully implemented feature.

@totomomo18
Copy link

totomomo18 commented Dec 11, 2025

A clean install without your patch (because I dont know how to install it or compile and ide with a patch) and did the same test the folding sort of work with show only selected element and bracket still disappear it seem to be a bug that did happen before should I report it as a bug ? and to which repository ?

Does it also happen if you close and reopen the editors after setting the preference? Also, it would be useful to know the exact code you are using (with whitespace) and the folding configuration.

The folding is enabled in the preference screen with the default values I did not touch it
and the code is just a regular code written mostly by the eclipse wizard I just asked it to create a test class with a main method then I added a second blank function just to test the show only selected element

I tested it again with closing and opening the file and find something interesting the bug (meaning the disappearing on ending bracket bug) does not always happen

if I close the editor than reopen it when the show only selected element is on I get all the methods in the file and when I focus on one method using the outline view I get to see only that method with the ending bracket so in this case the bug does not occur

It is only when I open a file while the show only selected element is off then I click the icon in the toolbar to invoke it (and nothing changes) and then I click the method I want to focus on the outline view and I see only that method without the ending bracket so in this case the bug occur

So it seems that only if you invoke show only selected element on a file is already open and go to a method using the outline view the bug happen and the ending bracket disappear and this is a bug

should I report this bug ? and to who ?

Edit : One good thing from all of this even with the bug folding now works when you show only selected element is enabled so the changes you merged even without the patch did make a great difference so Thank You for that

@danthe1st
Copy link
Contributor Author

It is only when I open a file while the show only selected element is off then I click the icon in the toolbar to invoke it (and nothing changes) and then I click the method I want to focus on the outline view and I see only that method without the ending bracket so in this case the bug occur

Yes, that is what I am saying the whole time. The unintended behavior (which I don't consider to be a problem) is that the feature works if you enable the preference while editors are open (in fact, restarting the IDE should result in folding being disabled as well until the other PR is merged). When I tried it, I didn't have the situation with the closing } being hidden.

should I report this bug ?

I don't think it makes much sense to create a new issue anywhere. If you have reliably steps to reproduce it, feel free to comment it in the aforementioned PR (I guess just commenting here is fine as well) but by just typing similar code, it didn't seem to do anything for me (maybe it's Windows-specific/only happens with CRLF, I didn't check that situation due to me using Linux - maybe I can check that at some point).

@danthe1st
Copy link
Contributor Author

Yes, it's because of Windows line endings. I hope that I can take a look at that.

@totomomo18
Copy link

Thank you for your help I hope you fix it in the future I be waiting but you did make the folding work when show only selected is on so that is a great improvement and I be using that

@danthe1st
Copy link
Contributor Author

danthe1st commented Dec 15, 2025

@totomomo18 #3585 should fix that part.

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.

Allow external visible regions in ProjectionViewer

7 participants