-
Notifications
You must be signed in to change notification settings - Fork 95
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
Folding mechanism for while/for/if/... #1562
Folding mechanism for while/for/if/... #1562
Conversation
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/folding/DefaultJavaFoldingStructureProvider.java
Show resolved
Hide resolved
08cd1d9
to
afd4aed
Compare
Bug:
|
c2082f5
to
0390f1c
Compare
c1ac59f
to
80ee66d
Compare
d5cf645
to
a44a7e0
Compare
The test failures seem to be unrelated: https://ci.eclipse.org/jdt/job/eclipse.jdt.ui-github/job/PR-1562/21/testReport/ The only test that fails with age == 1 (i.e. in this PR) is java.lang.AssertionError:
Wrong bundles loaded:
- org.eclipse.jdt.junit
expected:<0> but was:<24>
at org.junit.Assert.fail(Assert.java:89)
at org.junit.Assert.failNotEquals(Assert.java:835)
at org.junit.Assert.assertEquals(Assert.java:647)
at org.eclipse.jdt.text.tests.PluginsNotLoadedTest.pluginsNotLoaded(PluginsNotLoadedTest.java:278)
... Does anyone know the reason for this failure? In the meantime @jakub-suliga, try with another force-push to re-trigger the checks and see if the failure persists. |
a44a7e0
to
b49f6c9
Compare
On a closer look, the test failures are because of the changes introduced in this PR. Run them locally and you will see it. Here's (part of) the console output when running !STACK 0
java.lang.ClassCastException: class org.eclipse.jdt.internal.core.ClassFile cannot be cast to class org.eclipse.jdt.core.ICompilationUnit (org.eclipse.jdt.internal.core.ClassFile and org.eclipse.jdt.core.ICompilationUnit are in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @21452f5e)
at org.eclipse.jdt.ui.text.folding.DefaultJavaFoldingStructureProvider.computeFoldingStructure(DefaultJavaFoldingStructureProvider.java:981)
at org.eclipse.jdt.ui.text.folding.DefaultJavaFoldingStructureProvider.update(DefaultJavaFoldingStructureProvider.java:907)
at org.eclipse.jdt.ui.text.folding.DefaultJavaFoldingStructureProvider.initialize(DefaultJavaFoldingStructureProvider.java:852)
at org.eclipse.jdt.ui.text.folding.DefaultJavaFoldingStructureProvider.handleProjectionEnabled(DefaultJavaFoldingStructureProvider.java:822)
at org.eclipse.jdt.ui.text.folding.DefaultJavaFoldingStructureProvider$ProjectionListener.projectionEnabled(DefaultJavaFoldingStructureProvider.java:700)
...
at org.eclipse.jdt.ui.tests.quickfix.AnnotateAssistTest1d5.testAnnotateReturn2(AnnotateAssistTest1d5.java:178)
... It seems the It would be interesting to know when exactly is |
d68c88b
to
baf2632
Compare
@iloveeclipse : Jakub and I were looking into the failed tests and we found the culprit: it was a Do you see any possible problem with this change? We couldn't come up with any but maybe you can? |
I can't guarantee I will have time next week, I'm overloaded. The feature itself seems to be useful, so if the new test also covers existing functionality & is green, why not merge? @jjohnstn : are you available to review this? |
34817f9
to
4ae83f5
Compare
@iloveeclipse Sure |
@jakub-suliga Just trying it out, it seems to work well. I tried the given test but it does not fold the switch statement or its cases. Is that expected or is that something that isn't working in my particular test? I ran into a major bug with folding on my Linux platform which is likely Linux specific. If I fold, then hover over the plus and then click on the hover to focus it; there is no way out but Esc. This closes the hover but the flashing cursor is missing and the window pointer can get changed to the window expansion characters if I am on the edges of the hover area at the time of escape. I got similar experiences sometimes after entering via F2 to get focus in the hover window, but it seemed better and I often got the flashing cursor back. Once the cursor was gone, I could only get it back by switching into another Eclipse and its editor and then switching back. Again, likely Fedora specific, but I ask in case you have Windows/Mac and can confirm that it doesn't occur for you. It is not caused by this PR. |
Never mind. I can see from the code that switch statements aren't covered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, code looks good, but 2 comments to address.
org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/folding/DefaultJavaFoldingStructureProvider.java
Show resolved
Hide resolved
org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/folding/FoldingTest.java
Outdated
Show resolved
Hide resolved
I didn't add the switch statements because they were a bit buggy due to the cases. I'll address this in a separate PR after the current one is merged. |
4ae83f5
to
557adaf
Compare
Hi @jakub-suliga Could you resolve the conflicts by rebasing (not merging) your patch on top of current master? You might need to force push the result. If I can verify you have fixed the comment problem and you have merged your new support into the version of FoldingTest with region testing, I think this patch can be merged. |
77fda25
to
a534c2f
Compare
Done |
a534c2f
to
7f12c93
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks @jakub-suliga
@jakub-suliga I have marked the PR as noteworthy. Do you want to take a stab at adding a N&N entry or would you prefer I do it? A N&N entry would require a PR for [email protected]:eclipse-platform/www.eclipse.org-eclipse.git |
@jjohnstn I made a mistake. This PR contained both a bug fix (#1939) and a new feature, and they were combined in a single commit. Unfortunately, I forgot to mention this. Since the fixes are already included with the merge, the PR #1939 is currently unnecessary. |
Problem:
Currently, there is no folding mechanism for while/for/if/switch-case statements in Eclipse. VSCode and IntelliJ support a folding mechanism for these statements. Therefore, I have created a method that implements this folding mechanism. This is also an open issue: #1426. In addition, I deleted some commented-out code from 2007.
Before:
![image](https://private-user-images.githubusercontent.com/66252366/352453814-396b4061-9254-4896-b16a-f245026a0119.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0NDI0MjcsIm5iZiI6MTczOTQ0MjEyNywicGF0aCI6Ii82NjI1MjM2Ni8zNTI0NTM4MTQtMzk2YjQwNjEtOTI1NC00ODk2LWIxNmEtZjI0NTAyNmEwMTE5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEzVDEwMjIwN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWM1NWMxZDBkOGM0OTgzMGJhNTgwYTQ3YzkxZTAyNWU3MjhhZDYxM2U0NzVmZjA0ODBhMGJkMzhhZmU5N2UwZGYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.Z0cLM0XTA1I55nHP_OGN2LBgTsWVJTqyOBcpISrutPo)
After:
![image](https://private-user-images.githubusercontent.com/66252366/352454316-406f91c0-de52-4707-a611-c8016cb31245.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0NDI0MjcsIm5iZiI6MTczOTQ0MjEyNywicGF0aCI6Ii82NjI1MjM2Ni8zNTI0NTQzMTYtNDA2ZjkxYzAtZGU1Mi00NzA3LWE2MTEtYzgwMTZjYjMxMjQ1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEzVDEwMjIwN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTdlOGI3NWZlMGUzYzVhYjg0MzVlODc3NzMxNDg2MDNhODY5ODFiZjI4MDNmZjQ1NDNiOGZiOTFjMWQwNDAwYTAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.ZpE8sicAXBB4rpjj6MKRJ0aROIN-8SYFP5pFvX1bdZs)
How to test:
Here is a small program you can use to test:
Bugs: