Skip to content

Conversation

danthe1st
Copy link
Contributor

@danthe1st danthe1st commented Jun 29, 2025

Fixes #2264
Depends on eclipse-platform/eclipse.platform.ui#3074 (Is it necessary to change the version requirements in some way even if I am not depending on any new API?)
Depends on #2410 for this to work correctly with extended folding That dependency PR has been merged.

I think this should be tested with JDT-UI (with this PR) before eclipse-platform/eclipse.platform.ui#3074 is merged.

What it does

This PR enables folding when Window > Preferences > Java > Editor > Only show the selected Java element is enabled.

This depends on eclipse-platform/eclipse.platform.ui#3074 to work correctly.

How to test

  • Include Allow using visible regions with projections eclipse-platform/eclipse.platform.ui#3074
  • Enable Window > Preferences > Java > Editor > Only show the selected Java element
  • Enable folding in Window > Preferences > Java > Editor > Folding
  • Open a Java file
  • Folding should work
  • Select an element in the outline
  • Observe that only the selected element is shown in the editor.
  • Folding should still work
  • All of that should work with and without extended folding or custom folding regions. Editing the file shouldn't break it.

Author checklist

@danthe1st danthe1st marked this pull request as draft June 29, 2025 14:29
@danthe1st danthe1st marked this pull request as ready for review June 30, 2025 19:06
@danthe1st
Copy link
Contributor Author

I wrote some basic tests for the PR in eclipse.platform.ui. Is it also necessary to add integration tests in JDT-UI for this change?

@iloveeclipse
Copy link
Member

I wrote some basic tests for the PR in eclipse.platform.ui. Is it also necessary to add integration tests in JDT-UI for this change?

If possible, regression test for original problem?

@danthe1st danthe1st force-pushed the folding-selected-regions branch from 6967565 to a6a006f Compare June 30, 2025 19:27
@danthe1st
Copy link
Contributor Author

danthe1st commented Jun 30, 2025

If possible, regression test for original problem?

I added a test that ensures folding is active (even though I am not sure whether this is actually a bug I'm fixing or more implementing a feature/enhancement).

But note that in order to work correctly, the other PR would need to be merged/integrated first (and my test wouldn't detect that currently).

@danthe1st danthe1st force-pushed the folding-selected-regions branch 4 times, most recently from f8e0768 to 84fa6a1 Compare July 5, 2025 12:27
@danthe1st
Copy link
Contributor Author

danthe1st commented Jul 5, 2025

The test failure should be because this depends on eclipse-platform/eclipse.platform.ui#3074 which is not merged.

@danthe1st
Copy link
Contributor Author

The changes I made to DefaultJavaFoldingStructureProvider (making sure the IJavaElement is present) are necessary because it uses the IJavaElement to determine which folding regions are equal. Without this, it tries to update the existing folding projection annotations in a way that caused issues with my change (I think it tried to set existing folding regions to other ones).

@danthe1st danthe1st force-pushed the folding-selected-regions branch 5 times, most recently from ef87738 to 2cc9c2d Compare July 6, 2025 09:13
@danthe1st
Copy link
Contributor Author

danthe1st commented Jul 7, 2025

In situations where #2327 occurs and that region is added/removed when editing the editor, the parts after the visible region can become visible but that's fixed by that PR.

Other than that, I think this PR and eclipse-platform/eclipse.platform.ui#3074 are ready for someone to take a look at it.

@danthe1st danthe1st force-pushed the folding-selected-regions branch from 2cc9c2d to ebe65ee Compare July 10, 2025 16:49
@danthe1st
Copy link
Contributor Author

Would @iloveeclipse or someone else care to review these two PRs at some point?

@danthe1st danthe1st force-pushed the folding-selected-regions branch 2 times, most recently from 1b8ff59 to 36e790f Compare July 22, 2025 16:48
@iloveeclipse
Copy link
Member

Seem to work fine except the binary types (e.g. java.lang.String etc), I guess similar change like it was in JavaEditor is needed for ClassFileEditor.

@danthe1st danthe1st force-pushed the folding-selected-regions branch from 36e790f to 8e29d7c Compare July 23, 2025 14:18
@danthe1st
Copy link
Contributor Author

danthe1st commented Jul 23, 2025

Seem to work fine except the binary types (e.g. java.lang.String etc), I guess similar change like it was in JavaEditor is needed for ClassFileEditor.

Did the "Only show the selected Java element" option ever work with the Class File Editor? I didn't see that doing anything without my change and this PR doesn't seem to impact that.

@iloveeclipse
Copy link
Member

Seem to work fine except the binary types (e.g. java.lang.String etc), I guess similar change like it was in JavaEditor is needed for ClassFileEditor.

Did the "Only show the selected Java element" option ever work with the Class File Editor? I didn't see that doing anything without my change and this PR doesn't seem to impact that.

Honestly, no idea, I never used this "Only show the selected Java element" option, just assumed it should work there too :-)
So if it wasn't ther ebefore, don't care!

@danthe1st danthe1st force-pushed the folding-selected-regions branch from 8e29d7c to 98e8c31 Compare July 27, 2025 09:34
@danthe1st danthe1st force-pushed the folding-selected-regions branch 4 times, most recently from b36140c to a9036dc Compare August 3, 2025 10:21
@danthe1st
Copy link
Contributor Author

The changes to DefaultJavaFoldingStructureProvider (and CustomFoldingRegionTest) are necessary to prevent issues with changing the document with enhanced folding in cases like this:

// region outer

class SomeClass {
    // region inner
    void someMethod() {
        // content
    }
    // endregion
}

// endregion

That class would have the following issues when the file is modified:

  • With the changes to allow folding with "Only show selected Java element" without the changes I made to DefaultJavaFoldingStructureProvider, if someMethod is selected (and only that is shown), editing the code results in the full inner region being shown
  • Even without this PR/in the current master (or without the changes to DefaultJavaFoldingStructureProvider), if region outer is collapsed, editing the file expands it

The reason this happens is that it tries to "update" the outer region with the inner region or vice-versa (it confuses the folding regions with each other) so it re-expands the old folding region.

If wanted, I could factor out this fix to its own PR.

@danthe1st
Copy link
Contributor Author

danthe1st commented Aug 5, 2025

I have factored out the other bugfix into #2410 because smaller changes are typically preferred. This PR now only contains the logic for folding with "Only show the selected Java element".
I also updated the PR description.

Edit: That change is merged now.

@danthe1st danthe1st force-pushed the folding-selected-regions branch from ff0ff09 to b4d8551 Compare August 15, 2025 20:23
@danthe1st danthe1st force-pushed the folding-selected-regions branch from b4d8551 to f6c5035 Compare September 2, 2025 15:55
@eclipse-jdt-bot
Copy link
Contributor

This pull request changes some projects for the first time in this development cycle.
Therefore the following files need a version increment:

org.eclipse.jdt.text.tests/META-INF/MANIFEST.MF
org.eclipse.jdt.text.tests/pom.xml
org.eclipse.jdt.ui/META-INF/MANIFEST.MF
org.eclipse.jdt.ui/pom.xml

An additional commit containing all the necessary changes was pushed to the top of this PR's branch. To obtain these changes (for example if you want to push more changes) either fetch from your fork or apply the git patch.

Git patch
From e630ad7489024e7f982099c5da270b5aebbb467e Mon Sep 17 00:00:00 2001
From: Eclipse JDT Bot <[email protected]>
Date: Tue, 2 Sep 2025 16:00:34 +0000
Subject: [PATCH] Version bump(s) for 4.38 stream


diff --git a/org.eclipse.jdt.text.tests/META-INF/MANIFEST.MF b/org.eclipse.jdt.text.tests/META-INF/MANIFEST.MF
index 819c467448..7ba7965716 100644
--- a/org.eclipse.jdt.text.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.text.tests/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Automatic-Module-Name: org.eclipse.jdt.text.tests
 Bundle-ManifestVersion: 2
 Bundle-Name: %Plugin.name
 Bundle-SymbolicName: org.eclipse.jdt.text.tests;singleton:=true
-Bundle-Version: 3.15.200.qualifier
+Bundle-Version: 3.15.300.qualifier
 Bundle-Activator: org.eclipse.jdt.text.tests.JdtTextTestPlugin
 Bundle-ActivationPolicy: lazy
 Bundle-Vendor: %Plugin.providerName
diff --git a/org.eclipse.jdt.text.tests/pom.xml b/org.eclipse.jdt.text.tests/pom.xml
index 219999036e..c6742bad41 100644
--- a/org.eclipse.jdt.text.tests/pom.xml
+++ b/org.eclipse.jdt.text.tests/pom.xml
@@ -20,7 +20,7 @@
   </parent>
   <groupId>org.eclipse.jdt</groupId>
   <artifactId>org.eclipse.jdt.text.tests</artifactId>
-  <version>3.15.200-SNAPSHOT</version>
+  <version>3.15.300-SNAPSHOT</version>
   <packaging>eclipse-test-plugin</packaging>
 
   <properties>
diff --git a/org.eclipse.jdt.ui/META-INF/MANIFEST.MF b/org.eclipse.jdt.ui/META-INF/MANIFEST.MF
index 53f1b0d306..a5dc720767 100644
--- a/org.eclipse.jdt.ui/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.ui/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Automatic-Module-Name: org.eclipse.jdt.ui
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.jdt.ui; singleton:=true
-Bundle-Version: 3.35.100.qualifier
+Bundle-Version: 3.35.200.qualifier
 Bundle-Activator: org.eclipse.jdt.internal.ui.JavaPlugin
 Bundle-ActivationPolicy: lazy
 Bundle-Vendor: %providerName
diff --git a/org.eclipse.jdt.ui/pom.xml b/org.eclipse.jdt.ui/pom.xml
index e81c09a125..fa432d58f4 100644
--- a/org.eclipse.jdt.ui/pom.xml
+++ b/org.eclipse.jdt.ui/pom.xml
@@ -18,7 +18,7 @@
   </parent>
   <groupId>org.eclipse.jdt</groupId>
   <artifactId>org.eclipse.jdt.ui</artifactId>
-  <version>3.35.100-SNAPSHOT</version>
+  <version>3.35.200-SNAPSHOT</version>
   <packaging>eclipse-plugin</packaging>
 
 	<build>
-- 
2.51.0

Further information are available in Common Build Issues - Missing version increments.

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.

Eclipse new folding feature does not work when use show only selected element feature
3 participants