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 not necessary any more since that's merged, just make sure to use the latest I-build of eclipse.platform.ui
  • 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 from 61996c0 to 67e0c15 Compare September 12, 2025 19:04
@danthe1st danthe1st force-pushed the folding-selected-regions branch from 67e0c15 to 934e63e Compare September 25, 2025 14:36
@jjohnstn
Copy link
Contributor

Hi @danthe1st I'd be happy to review this once the platform UI patch is in.

@danthe1st danthe1st force-pushed the folding-selected-regions branch 3 times, most recently from 2cd167d to 25b2c85 Compare October 10, 2025 14:59
@danthe1st danthe1st force-pushed the folding-selected-regions branch from 25b2c85 to 88ac1b3 Compare October 20, 2025 17:32
@danthe1st
Copy link
Contributor Author

danthe1st commented Oct 20, 2025

Even though the JDT-UI platform-UI patch is in and the regressions caused by it have been fixed, it is still possible that it gets reverted if it causes more issues so it might be better to see and keep this for 2026-03. Alternatively, it could also be reviewed now.

@iloveeclipse
Copy link
Member

Even though the JDT-UI patch is in

You probably mean Platform UI patch?

Alternatively, it could also be reviewed now.

This would be better tha patch here is small enough and shouldn't be a problem to revert.

@danthe1st
Copy link
Contributor Author

danthe1st commented Oct 20, 2025

You probably mean Platform UI patch?

Yes, my fault (edited)

This would be better tha patch here is small enough and shouldn't be a problem to revert.

I see. @jjohnstn would you still want to review this now?

@danthe1st
Copy link
Contributor Author

danthe1st commented Oct 20, 2025

@jjohnstn ^ Sorry I originally messed up the ping

@danthe1st danthe1st force-pushed the folding-selected-regions branch from 88ac1b3 to 8e88fc9 Compare October 20, 2025 19:37
@danthe1st
Copy link
Contributor Author

^ rebased, fixed merge conflicts

@jjohnstn
Copy link
Contributor

I am seeing a issue when testing. If I have:

public class TestFolding {

	// region

	void test() {
		// region A
		// endregion A

	}
	void test2() {

	}

	void test2a() {

	}
	void test3() {}

	// endregion

	// region2

	void test4() {

	}

	// endregion2
}

When I select test() in the outline view, it shows test() only but it also shows the // region comment above it (AST elements get tied to line comments above them and on the same line). It is recognized as a custom folding comment but clicking on it does not hide the test() method. It adds the end-of-line stuff in a normal folding on all of the test() lines. I can confirm that folding within test() works fine.

Copy link
Contributor

@jjohnstn jjohnstn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See main-line comment

@danthe1st
Copy link
Contributor Author

When I select test() in the outline view, it shows test() only but it also shows the // region comment above it (AST elements get tied to line comments above them and on the same line). It is recognized as a custom folding comment but clicking on it does not hide the test() method. It adds the end-of-line stuff in a normal folding on all of the test() lines. I can confirm that folding within test() works fine.

When writing the Platform-UI patch, I ensured that it is not possible to fold anything outside of the visible region (as it didn't make sense IMO). I think I can provide another PR there that ensures that these annotations are hidden.

@danthe1st
Copy link
Contributor Author

I created eclipse-platform/eclipse.platform.ui#3423 to fix this issue.

@danthe1st danthe1st force-pushed the folding-selected-regions branch from 8e88fc9 to c06ab2e Compare December 15, 2025 10:40
@danthe1st
Copy link
Contributor Author

danthe1st commented Dec 15, 2025

@jjohnstn Would you like to review this now for 2026-03? There are still eclipse-platform/eclipse.platform.ui#3457 (small GUI change), eclipse-platform/eclipse.platform.ui#3456 (fixing some exception) and eclipse-platform/eclipse.platform.ui#3585 (fixing too much being hidden at the end with Windows line endings) but I think these shouldn't block this review (much).

Copy link
Contributor

@jjohnstn jjohnstn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@jjohnstn jjohnstn merged commit d000f25 into eclipse-jdt:master Dec 16, 2025
13 checks passed
@danthe1st danthe1st deleted the folding-selected-regions branch December 16, 2025 07:43
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

4 participants