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

import regions not computed for .class files #2133

Closed
fbricon opened this issue Sep 27, 2021 · 5 comments · Fixed by eclipse-jdtls/eclipse.jdt.ls#2281
Closed

import regions not computed for .class files #2133

fbricon opened this issue Sep 27, 2021 · 5 comments · Fixed by eclipse-jdtls/eclipse.jdt.ls#2281

Comments

@fbricon
Copy link
Collaborator

fbricon commented Sep 27, 2021

When opening a .class file, the import statements are not folded by default, with "editor.foldingImportsByDefault": true. Seems you can't even fold the import block manually. Something's fishy here.
I noticed that in #2132 (comment)

@fbricon fbricon added the bug label Sep 27, 2021
@rgrunber
Copy link
Member

I just noticed the same behaviour in Eclipse as well for classfiles. Looking at the code, it seems like we check for the IImportContainer child element of an ICompilationUnit to get the folding range. However, the IClassfile doesn't seem to have such a child element.

@rgrunber
Copy link
Member

rgrunber commented Sep 27, 2021

@rgrunber
Copy link
Member

rgrunber commented Sep 29, 2021

Just a note, this is still possible to implement. Just not from the Java model side. On the AST side, we could find the node corresponding the import statements, and use those offsets to generate the folding range. I would just be curious if the Java model side has anything at all to accomplish this.

Update : a classfile shouldn't have an AST, but if we have the sources for the classfile, I don't see why we couldn't just generate one and go by the offsets. Hacky, but if we really wanted this, it could work. Alternatively we could investigate more upstream.

@baincd
Copy link

baincd commented Mar 26, 2022

As a workaround, I have created a VS Code extension that adds a folding region for imports on .class files: https://marketplace.visualstudio.com/items?itemName=baincd.java-class-imports-folding

@rgrunber
Copy link
Member

rgrunber commented Oct 24, 2022

Instead of using the AST parsing facility, @JessicaJHee went with using the scanner's ITerminalSymbols.TokenNameimport to detect the import range. We do use the scanner for other parts of the folding range computations. This should work as expected now.

baincd added a commit to baincd/vscode-java-class-imports-folding that referenced this issue Nov 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants