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

Add support for .class files #2679

Closed
FileOfName opened this issue Sep 17, 2022 · 5 comments · Fixed by eclipse-jdtls/eclipse.jdt.ls#2515 or #2985
Closed

Add support for .class files #2679

FileOfName opened this issue Sep 17, 2022 · 5 comments · Fixed by eclipse-jdtls/eclipse.jdt.ls#2515 or #2985

Comments

@FileOfName
Copy link

Currently, you can't open .class files in vscode. To be clear I don't mean the "Go To Definition" action I mean plain .class files. If you try and open one then it'll give you a warning. I've found two extensions that sound like they solved the problem but don't:

  1. Java Decompiler on "Go To Definition" decompiles the file if it's not already.
  2. Java CFR Decompiler decompiles the file into a new .java file but doesn't open it in a read-only editor which means I can edit it and every time I want to close it I get a popup saying "Do you want to save changes?".

The conclusion is that there is no convenient way of opening a decompiled .class file in vscode.

@rgrunber
Copy link
Member

Seems like exactly what #304 was suggesting. Looks like dgileadi/vscode-java-decompiler#3 mentions some of the issues you're seeing. Seems to me like this is something one of the decompiler extensions should be supporting.

@fbricon , has our view changed on this ?

@FileOfName
Copy link
Author

FileOfName commented Sep 24, 2022

@rgrunber

we're trying to focus on the Java editing experience.

In my opinion, a built-in class decompiler is part of the Java editing experience and either this extension or any other java decompiler extension should support it. For now, I need to use IntelliJ idea for java class files, which is not ideal because I would want to have all functionality in one ide.

@rgrunber
Copy link
Member

rgrunber commented Oct 4, 2022

We could potentially do what the document/definition request does at JDTUtils.searchDecompiledSources -> .. -> DisassemblerContentProvider.getContent(..). On the client side I think we'd just need to register a content provider for the .class files.

This might provide some basic support, though it would be nice to have a way to determine if we should be doing this, or simply letting some existing extension handle it.

@FileOfName
Copy link
Author

Eclipse and IntelliJ idea have it. Why should this extension not have it?

@rgrunber
Copy link
Member

rgrunber commented Mar 3, 2023

@JessicaJHee noted that this is going to require creating a custom text editor, because the text document provider only allows ownership of an entire scheme, but not certain files (eg. "*.class" of file scheme). See microsoft/vscode#116627

Update: Another idea we've been experimenting with is mapping the file://... Uri of the classfile to something like class:// (we can intercept the open with onDidChangeActiveTextEditor), and having a registered content provider for the class:// scheme. From there we can provide our own content. This approach would also get to take advantage of the various features already built into the default editor.
Current solution to deal with the opened .class file would be to call workbench.action.closeActiveEditor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment