From 51617c0805c4f09da1f07b87fa4835a49c9a89d9 Mon Sep 17 00:00:00 2001 From: Amrita kumari mishra Date: Sat, 28 Mar 2026 20:05:07 +0000 Subject: [PATCH] Fix: open .java file instead of .class during debugging when source is available --- src/javaClassEditor.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/javaClassEditor.ts b/src/javaClassEditor.ts index 2cf0f6bd0d..e50d18e02a 100644 --- a/src/javaClassEditor.ts +++ b/src/javaClassEditor.ts @@ -29,7 +29,22 @@ export class JavaClassEditorProvider implements vscode.CustomReadonlyEditorProvi enableScripts: true, localResourceRoots: [Uri.joinPath(Uri.parse(this.context.extensionPath), 'webview-resources')] }; - const classUri = Uri.parse((document.uri.toString()).replace(/^file/, "class")); + const uriString = document.uri?.toString(); + let targetUri: Uri; + + if (!uriString) { + targetUri = document.uri; // Fallback safety for null/undefined URIs + } else { + const fileUri = Uri.parse(uriString.replace(/^class/, "file")); + try { + // Attempt to open as a standard text document first + await vscode.workspace.openTextDocument(fileUri); + targetUri = fileUri; + } catch { + // Fallback to the 'class' scheme if the file document can't be opened + targetUri = Uri.parse(uriString.replace(/^file/, "class")); + } + } const styleUri = Uri.file( path.join(this.context.extensionPath, 'webview-resources', 'button.css') ); @@ -52,7 +67,7 @@ export class JavaClassEditorProvider implements vscode.CustomReadonlyEditorProvi switch (message.command) { case 'decompiled': webviewPanel.dispose(); - window.showTextDocument(classUri, { preview: false }); + window.showTextDocument(targetUri, { preview: false }); return; } }, undefined, this.context.subscriptions);