vscode-java
vscode-java copied to clipboard
Add support for .class files
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:
- Java Decompiler on "Go To Definition" decompiles the file if it's not already.
- 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.
Seems like exactly what https://github.com/redhat-developer/vscode-java/issues/304 was suggesting. Looks like https://github.com/dgileadi/vscode-java-decompiler/issues/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 ?
@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.
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.
Eclipse and IntelliJ idea have it. Why should this extension not have it?
@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 https://github.com/microsoft/vscode/issues/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