From 1643b7b1455e6aa99f0157ccb2f1fbd54373f088 Mon Sep 17 00:00:00 2001 From: Burhanuddin Vora Date: Fri, 13 Nov 2026 22:24:57 +0530 Subject: [PATCH 1/7] feat: recommend JBang for single Java file usage When a user opens a single Java file with no workspace folder, or a workspace folder with just a single Java file, show an information message recommending the JBang extension for running Java scripts. Includes option to install the jbang-vscode extension from the marketplace, and a 'Don't Show Again' option to suppress future notifications. Fixes #3111 --- package.json | 5 +++++ package.nls.json | 3 ++- src/commands.ts | 5 +++++ src/extension.ts | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 99513c139..e1861da37 100644 --- a/package.json +++ b/package.json @@ -1900,6 +1900,11 @@ "command": "java.action.copyFullyQualifiedName", "title": "%java.action.copyFullyQualifiedName%", "category": "Java" + }, + { + "command": "java.jbang.recommend", + "title": "%java.jbang.recommend%", + "category": "Java" } ], "keybindings": [ diff --git a/package.nls.json b/package.nls.json index 8709bc914..9a59ca628 100644 --- a/package.nls.json +++ b/package.nls.json @@ -26,5 +26,6 @@ "java.change.searchScope": "Change Search Scope", "java.action.showExtendedOutline": "Open Extended Outline", "java.runtimes.add": "Add Java Runtime", - "java.action.copyFullyQualifiedName": "Copy Fully Qualified Name" + "java.action.copyFullyQualifiedName": "Copy Fully Qualified Name", + "java.jbang.recommend": "Recommend JBang" } diff --git a/src/commands.ts b/src/commands.ts index 533372c73..e46ad2cd7 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -368,6 +368,11 @@ export namespace Commands { */ export const COPY_FULLY_QUALIFIED_NAME = 'java.action.copyFullyQualifiedName'; export const GET_FULLY_QUALIFIED_NAME = 'java.getFullyQualifiedName'; + + /** + * Recommend JBang for single Java file usage. + */ + export const JBANG_RECOMMEND = 'java.jbang.recommend'; } /** diff --git a/src/extension.ts b/src/extension.ts index 0fcdb138a..7cde39ff8 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -437,6 +437,15 @@ export async function activate(context: ExtensionContext): Promise cleanWorkspaceExists ); + // Recommend JBang when working with a single Java file (issue #3111) + void showJBangRecommendation(context); + + context.subscriptions.push(workspace.onDidOpenTextDocument(async (document) => { + if (document.languageId === 'java') { + await showJBangRecommendation(context); + } + })); + return apiManager.getApiInstance(); } @@ -1412,3 +1421,50 @@ function addRevealCommand(client: LanguageClient, codeAction: CodeAction, lspEdi } return codeAction; } + +const JBANG_RECOMMENDATION_KEY = 'jbangRecommendationShown'; +const JBANG_EXTENSION_ID = 'jbangdev.jbang-vscode'; +const JBANG_MARKETPLACE_URL = 'https://marketplace.visualstudio.com/items?itemName=jbangdev.jbang-vscode'; + +function shouldRecommendJBang(): boolean { + // Case 1: No workspace folder (standalone file mode) + if (!workspace.workspaceFolders) { + return true; + } + // Case 2: Workspace folder with just a single Java file + if (workspace.workspaceFolders.length === 1) { + const javaFileCount = workspace.textDocuments.filter(doc => doc.languageId === 'java').length; + if (javaFileCount <= 1) { + return true; + } + } + return false; +} + +async function showJBangRecommendation(context: ExtensionContext): Promise { + const alreadyShown = context.globalState.get(JBANG_RECOMMENDATION_KEY, false); + if (alreadyShown) { + return; + } + + if (!shouldRecommendJBang()) { + return; + } + + const install = 'Install JBang'; + const maybeLater = 'Maybe Later'; + const dontShowAgain = "Don't Show Again"; + + const choice = await window.showInformationMessage( + 'You are working with a single Java file. JBang makes it easy to run Java scripts. Would you like to install the JBang extension?', + install, maybeLater, dontShowAgain + ); + + if (choice === install) { + await commands.executeCommand(Commands.OPEN_BROWSER, Uri.parse(JBANG_MARKETPLACE_URL)); + } + + if (choice === dontShowAgain || choice === install) { + await context.globalState.update(JBANG_RECOMMENDATION_KEY, true); + } +} From d92d2df1611c709de5acf2b34ac47b02a5140b16 Mon Sep 17 00:00:00 2001 From: Burhanuddin Vora Date: Sat, 14 Nov 2026 15:00:46 +0530 Subject: [PATCH 2/7] fix: Replaced the browser-opening call with the direct install command. Signed-off-by: Burhanuddin Vora --- src/extension.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 7cde39ff8..c390cade6 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1424,7 +1424,6 @@ function addRevealCommand(client: LanguageClient, codeAction: CodeAction, lspEdi const JBANG_RECOMMENDATION_KEY = 'jbangRecommendationShown'; const JBANG_EXTENSION_ID = 'jbangdev.jbang-vscode'; -const JBANG_MARKETPLACE_URL = 'https://marketplace.visualstudio.com/items?itemName=jbangdev.jbang-vscode'; function shouldRecommendJBang(): boolean { // Case 1: No workspace folder (standalone file mode) @@ -1461,7 +1460,7 @@ async function showJBangRecommendation(context: ExtensionContext): Promise ); if (choice === install) { - await commands.executeCommand(Commands.OPEN_BROWSER, Uri.parse(JBANG_MARKETPLACE_URL)); + await commands.executeCommand('workbench.extensions.installExtension', JBANG_EXTENSION_ID); } if (choice === dontShowAgain || choice === install) { From 3fd31b6316bbfe637f1c398294013837642a47f3 Mon Sep 17 00:00:00 2001 From: Burhanuddin Vora Date: Mon, 23 Nov 2026 23:34:05 +0530 Subject: [PATCH 3/7] Remove unregistered java.jbang.recommend command The java.jbang.recommend command was declared in package.json, src/commands.ts, and package.nls.json but never registered via commands.registerCommand in extension.ts, so it had no handler. The existing showJBangRecommendation() activation logic (extension.ts) is a separate, independent feature that surfaces a notification for single-file Java usage and remains unchanged. --- package.json | 5 ----- package.nls.json | 3 +-- src/commands.ts | 4 ---- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/package.json b/package.json index e1861da37..99513c139 100644 --- a/package.json +++ b/package.json @@ -1900,11 +1900,6 @@ "command": "java.action.copyFullyQualifiedName", "title": "%java.action.copyFullyQualifiedName%", "category": "Java" - }, - { - "command": "java.jbang.recommend", - "title": "%java.jbang.recommend%", - "category": "Java" } ], "keybindings": [ diff --git a/package.nls.json b/package.nls.json index 9a59ca628..8709bc914 100644 --- a/package.nls.json +++ b/package.nls.json @@ -26,6 +26,5 @@ "java.change.searchScope": "Change Search Scope", "java.action.showExtendedOutline": "Open Extended Outline", "java.runtimes.add": "Add Java Runtime", - "java.action.copyFullyQualifiedName": "Copy Fully Qualified Name", - "java.jbang.recommend": "Recommend JBang" + "java.action.copyFullyQualifiedName": "Copy Fully Qualified Name" } diff --git a/src/commands.ts b/src/commands.ts index e46ad2cd7..99a82dcb4 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -369,10 +369,6 @@ export namespace Commands { export const COPY_FULLY_QUALIFIED_NAME = 'java.action.copyFullyQualifiedName'; export const GET_FULLY_QUALIFIED_NAME = 'java.getFullyQualifiedName'; - /** - * Recommend JBang for single Java file usage. - */ - export const JBANG_RECOMMEND = 'java.jbang.recommend'; } /** From 915fcf6c44d864900e6b1e447493dfb163e0cd04 Mon Sep 17 00:00:00 2001 From: Burhanuddin Vora Date: Mon, 23 Nov 2026 23:37:47 +0530 Subject: [PATCH 4/7] remvoed unnecessary changes --- src/commands.ts | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/commands.ts b/src/commands.ts index 99a82dcb4..45844cb6c 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -200,7 +200,7 @@ export namespace Commands { /** * Custom paste action in files explorer */ - export const FILESEXPLORER_ONPASTE = 'java.action.filesExplorerPasteAction'; + export const FILESEXPLORER_ONPASTE = 'java.action.filesExplorerPasteAction'; /** * Choose type to import. */ @@ -257,10 +257,10 @@ export namespace Commands { * Command to switch between standard mode and lightweight mode. */ export const SWITCH_SERVER_MODE = 'java.server.mode.switch'; - /** + /** * Command to restart the language server. */ - export const RESTART_LANGUAGE_SERVER = 'java.server.restart'; + export const RESTART_LANGUAGE_SERVER = 'java.server.restart'; export const LEARN_MORE_ABOUT_REFACTORING = '_java.learnMoreAboutRefactorings'; @@ -348,27 +348,26 @@ export namespace Commands { */ export const GET_VISIBLE_EDITOR_CONTENT = '_java.getVisibleEditorContent'; - /** + /** * Get troubleshooting info command in jdt.ls */ export const GET_TROUBLESHOOTING_INFO = 'java.getTroubleshootingInfo'; - /** - * Open Java Dashboard - */ - export const OPEN_JAVA_DASHBOARD = 'java.dashboard.open'; + /** + * Open Java Dashboard + */ + export const OPEN_JAVA_DASHBOARD = 'java.dashboard.open'; /** * Add Java Runtime */ export const ADD_JAVA_RUNTIME = 'java.runtimes.add'; - /** + /** * Copy fully qualified name. */ - export const COPY_FULLY_QUALIFIED_NAME = 'java.action.copyFullyQualifiedName'; - export const GET_FULLY_QUALIFIED_NAME = 'java.getFullyQualifiedName'; - + export const COPY_FULLY_QUALIFIED_NAME = 'java.action.copyFullyQualifiedName'; + export const GET_FULLY_QUALIFIED_NAME = 'java.getFullyQualifiedName'; } /** From c7741d1679a2b422932513cef92434f1c0976c68 Mon Sep 17 00:00:00 2001 From: Burhanuddin Vora Date: Mon, 23 Nov 2026 23:40:57 +0530 Subject: [PATCH 5/7] remvoed unnecessary changes --- src/commands.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/commands.ts b/src/commands.ts index 45844cb6c..aec06210b 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -200,7 +200,7 @@ export namespace Commands { /** * Custom paste action in files explorer */ - export const FILESEXPLORER_ONPASTE = 'java.action.filesExplorerPasteAction'; + export const FILESEXPLORER_ONPASTE = 'java.action.filesExplorerPasteAction'; /** * Choose type to import. */ @@ -257,10 +257,10 @@ export namespace Commands { * Command to switch between standard mode and lightweight mode. */ export const SWITCH_SERVER_MODE = 'java.server.mode.switch'; - /** + /** * Command to restart the language server. */ - export const RESTART_LANGUAGE_SERVER = 'java.server.restart'; + export const RESTART_LANGUAGE_SERVER = 'java.server.restart'; export const LEARN_MORE_ABOUT_REFACTORING = '_java.learnMoreAboutRefactorings'; @@ -348,26 +348,26 @@ export namespace Commands { */ export const GET_VISIBLE_EDITOR_CONTENT = '_java.getVisibleEditorContent'; - /** + /** * Get troubleshooting info command in jdt.ls */ export const GET_TROUBLESHOOTING_INFO = 'java.getTroubleshootingInfo'; - /** - * Open Java Dashboard - */ - export const OPEN_JAVA_DASHBOARD = 'java.dashboard.open'; + /** + * Open Java Dashboard + */ + export const OPEN_JAVA_DASHBOARD = 'java.dashboard.open'; /** * Add Java Runtime */ export const ADD_JAVA_RUNTIME = 'java.runtimes.add'; - /** + /** * Copy fully qualified name. */ - export const COPY_FULLY_QUALIFIED_NAME = 'java.action.copyFullyQualifiedName'; - export const GET_FULLY_QUALIFIED_NAME = 'java.getFullyQualifiedName'; + export const COPY_FULLY_QUALIFIED_NAME = 'java.action.copyFullyQualifiedName'; + export const GET_FULLY_QUALIFIED_NAME = 'java.getFullyQualifiedName'; } /** @@ -377,4 +377,4 @@ export namespace CommandTitle { export const OPEN_JAVA_SETTINGS = "$(settings-gear) Open Java Settings"; export const OPEN_LOGS = "$(output) Open Logs"; export const CLEAN_WORKSPACE_CACHE = "$(trash) Clean Workspace Cache..."; -} +} \ No newline at end of file From b0421f866ebae1d6e0f9b05a3b51031fdd84ce2d Mon Sep 17 00:00:00 2001 From: Burhanuddin Vora Date: Mon, 23 Nov 2026 23:47:04 +0530 Subject: [PATCH 6/7] fix: restore proper indentation and newline in src/commands.ts Revert unintended indentation changes (spaces to tabs) and restore the missing trailing newline at end of file. The intentional removal of the unregistered java.jbang.recommend command is preserved. --- src/commands.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/commands.ts b/src/commands.ts index aec06210b..45844cb6c 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -200,7 +200,7 @@ export namespace Commands { /** * Custom paste action in files explorer */ - export const FILESEXPLORER_ONPASTE = 'java.action.filesExplorerPasteAction'; + export const FILESEXPLORER_ONPASTE = 'java.action.filesExplorerPasteAction'; /** * Choose type to import. */ @@ -257,10 +257,10 @@ export namespace Commands { * Command to switch between standard mode and lightweight mode. */ export const SWITCH_SERVER_MODE = 'java.server.mode.switch'; - /** + /** * Command to restart the language server. */ - export const RESTART_LANGUAGE_SERVER = 'java.server.restart'; + export const RESTART_LANGUAGE_SERVER = 'java.server.restart'; export const LEARN_MORE_ABOUT_REFACTORING = '_java.learnMoreAboutRefactorings'; @@ -348,26 +348,26 @@ export namespace Commands { */ export const GET_VISIBLE_EDITOR_CONTENT = '_java.getVisibleEditorContent'; - /** + /** * Get troubleshooting info command in jdt.ls */ export const GET_TROUBLESHOOTING_INFO = 'java.getTroubleshootingInfo'; - /** - * Open Java Dashboard - */ - export const OPEN_JAVA_DASHBOARD = 'java.dashboard.open'; + /** + * Open Java Dashboard + */ + export const OPEN_JAVA_DASHBOARD = 'java.dashboard.open'; /** * Add Java Runtime */ export const ADD_JAVA_RUNTIME = 'java.runtimes.add'; - /** + /** * Copy fully qualified name. */ - export const COPY_FULLY_QUALIFIED_NAME = 'java.action.copyFullyQualifiedName'; - export const GET_FULLY_QUALIFIED_NAME = 'java.getFullyQualifiedName'; + export const COPY_FULLY_QUALIFIED_NAME = 'java.action.copyFullyQualifiedName'; + export const GET_FULLY_QUALIFIED_NAME = 'java.getFullyQualifiedName'; } /** @@ -377,4 +377,4 @@ export namespace CommandTitle { export const OPEN_JAVA_SETTINGS = "$(settings-gear) Open Java Settings"; export const OPEN_LOGS = "$(output) Open Logs"; export const CLEAN_WORKSPACE_CACHE = "$(trash) Clean Workspace Cache..."; -} \ No newline at end of file +} From 7bd3a11428a64ce759c31cac73261f44fc42ae42 Mon Sep 17 00:00:00 2001 From: Burhanuddin Vora Date: Mon, 23 Nov 2026 23:52:08 +0530 Subject: [PATCH 7/7] fix: restore src/commands.ts from main branch Revert src/commands.ts to the main branch version, keeping only the package.json and package.nls.json changes that remove the unregistered java.jbang.recommend command declaration. --- src/commands.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/commands.ts b/src/commands.ts index 45844cb6c..533372c73 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -200,7 +200,7 @@ export namespace Commands { /** * Custom paste action in files explorer */ - export const FILESEXPLORER_ONPASTE = 'java.action.filesExplorerPasteAction'; + export const FILESEXPLORER_ONPASTE = 'java.action.filesExplorerPasteAction'; /** * Choose type to import. */ @@ -257,10 +257,10 @@ export namespace Commands { * Command to switch between standard mode and lightweight mode. */ export const SWITCH_SERVER_MODE = 'java.server.mode.switch'; - /** + /** * Command to restart the language server. */ - export const RESTART_LANGUAGE_SERVER = 'java.server.restart'; + export const RESTART_LANGUAGE_SERVER = 'java.server.restart'; export const LEARN_MORE_ABOUT_REFACTORING = '_java.learnMoreAboutRefactorings'; @@ -348,26 +348,26 @@ export namespace Commands { */ export const GET_VISIBLE_EDITOR_CONTENT = '_java.getVisibleEditorContent'; - /** + /** * Get troubleshooting info command in jdt.ls */ export const GET_TROUBLESHOOTING_INFO = 'java.getTroubleshootingInfo'; - /** - * Open Java Dashboard - */ - export const OPEN_JAVA_DASHBOARD = 'java.dashboard.open'; + /** + * Open Java Dashboard + */ + export const OPEN_JAVA_DASHBOARD = 'java.dashboard.open'; /** * Add Java Runtime */ export const ADD_JAVA_RUNTIME = 'java.runtimes.add'; - /** + /** * Copy fully qualified name. */ - export const COPY_FULLY_QUALIFIED_NAME = 'java.action.copyFullyQualifiedName'; - export const GET_FULLY_QUALIFIED_NAME = 'java.getFullyQualifiedName'; + export const COPY_FULLY_QUALIFIED_NAME = 'java.action.copyFullyQualifiedName'; + export const GET_FULLY_QUALIFIED_NAME = 'java.getFullyQualifiedName'; } /**