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

Show decompiled content directly on open .class file #3759

Closed
Eskibear opened this issue Sep 3, 2024 · 5 comments · Fixed by #3760
Closed

Show decompiled content directly on open .class file #3759

Eskibear opened this issue Sep 3, 2024 · 5 comments · Fixed by #3760

Comments

@Eskibear
Copy link
Contributor

Eskibear commented Sep 3, 2024

It's a feature request.

User case

I downloaded a .jar file, extracted it, and was inspecting class files in vscode (opening the extracted folder as root folder). The decompile functionality worked well. When I switched between different .class files I have to re-click the "Decompile Class File" again to see the content, which created a little bit overhead for me.
Is it possible that I can see the decompiled content directly (e.g. by turning on a setting)? That would create smoother user experience in this case.

@rgrunber
Copy link
Member

rgrunber commented Sep 3, 2024

@JessicaJHee , do you remember if there was any reason why we decided to use a button to activate the decompilation in #2985 ? Was it just to match how Eclipse was doing it ? If I remove it and just triggered the decompilation it seems to work. Seems I could just make a setting for it to skip the button.

@JessicaJHee
Copy link
Contributor

@rgrunber I believe it was because there wasn't a way to make the decompile request to jdt.ls from the custom editor without using some event triggered by the button. How were you triggering the decompilation after removing it?

@rgrunber
Copy link
Member

rgrunber commented Sep 3, 2024

I just did :

diff --git a/src/javaClassEditor.ts b/src/javaClassEditor.ts
index 053593c..22141e9 100644
--- a/src/javaClassEditor.ts
+++ b/src/javaClassEditor.ts
@@ -43,14 +43,10 @@ export class JavaClassEditorProvider implements vscode.CustomReadonlyEditorProvi
                <body>
                        <div class="center">
                                <p>This file is not displayed in the text editor because it is a Java class file. Click here to decompile and open.</p>
-                               <button id="btn"><center>Decompile Class File</center></button>
                        <div>
                        <script nonce="${nonce}">
                                const vscode = acquireVsCodeApi();
-                               document.getElementById("btn").addEventListener("click", decompiled);
-                               function decompiled() {
-                                       vscode.postMessage({ command: 'decompiled' });
-                               }
+                               vscode.postMessage({ command: 'decompiled' });
                        </script>
                </body>
                </html>

The page becomes unnecessary, but it does seem to work.

Maybe we did it because we wanted to mimic :

image

@JessicaJHee
Copy link
Contributor

@rgrunber Ahh I see, that might be the case. It does make sense to me to remove the page then, iirc there is a comment at the top of the decompiled file saying it was generated anyways 👍

@Eskibear
Copy link
Contributor Author

Eskibear commented Sep 4, 2024

Maybe we did it because we wanted to mimic :

VS Code shows this because showing a binary file with unknown encoding is not helpful in most cases. Here since we are "showing" .class files with well generated content, I don't think we need the extra step.

The only corner case I'm concerning is, if a user indeed wants to view binary content of .class file, we should not block them. I.e. allow them to re-open with a text editor, as below: (command palette -> View: Re-open Editor with ...)

image

Currently, the page with "Decompile Class File" button can be re-open with text editor, but the page with decompiled content cannot work with re-open, which is mainly because it's a content provider instead of a custom editor I guess. If that's the case, ideally what I expect is, to show decompiled class file content directly in this custom editor, then we have better user experience and it works smoothly with vscode's custom editor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

3 participants