diff --git a/package.json b/package.json index 10cdb5331..bc24a0191 100644 --- a/package.json +++ b/package.json @@ -83,6 +83,21 @@ "buildFileNames": ["build.gradle", "settings.gradle", "build.gradle.kts", "settings.gradle.kts"] } ], + "javaShortcuts": [ + { + "title": "$(settings-gear) Open Java Settings", + "command": "workbench.action.openSettings", + "arguments": ["java"] + }, + { + "title": "$(output) Open Logs", + "command": "java.open.logs" + }, + { + "title": "$(trash) Clean Workspace Cache...", + "command": "java.clean.workspace" + } + ], "semanticTokenTypes": [ { "id": "annotation", diff --git a/schemas/package.schema.json b/schemas/package.schema.json index 6b24ea87a..a74bd2a10 100644 --- a/schemas/package.schema.json +++ b/schemas/package.schema.json @@ -41,6 +41,27 @@ } } } + }, + "javaShortcuts": { + "type": "array", + "description": "Shortcuts to be listed when clicking server status bar item.", + "items": { + "type": "object", + "properties": { + "title": { + "description": "The title of the quick pick item.", + "type": "string" + }, + "command": { + "description": "The command to be executed when the quick pick is selected.", + "type": "string" + }, + "arguments": { + "description": "The arguments to be passed to the command.", + "type": "array" + } + } + } } } } diff --git a/src/extension.ts b/src/extension.ts index a41222feb..642122158 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -19,7 +19,7 @@ import { initializeLogFile, logger } from './log'; import { cleanupLombokCache } from "./lombokSupport"; import { markdownPreviewProvider } from "./markdownPreviewProvider"; import { OutputInfoCollector } from './outputInfoCollector'; -import { collectJavaExtensions, getBundlesToReload, isContributedPartUpdated } from './plugin'; +import { collectJavaExtensions, getBundlesToReload, getShortcuts, IJavaShortcut, isContributedPartUpdated } from './plugin'; import { registerClientProviders } from './providerDispatcher'; import { initialize as initializeRecommendation } from './recommendation'; import * as requirements from './requirements'; @@ -364,17 +364,13 @@ export async function activate(context: ExtensionContext): Promise commands.executeCommand(Commands.SHOW_SERVER_TASK_STATUS, true); } - items.push({ - label: CommandTitle.OPEN_JAVA_SETTINGS, - command: "workbench.action.openSettings", - args: ["java"], - }, { - label: CommandTitle.OPEN_LOGS, - command: Commands.OPEN_LOGS, - }, { - label: CommandTitle.CLEAN_WORKSPACE_CACHE, - command: Commands.CLEAN_WORKSPACE - }); + items.push(...getShortcuts().map((shortcut: IJavaShortcut) => { + return { + label: shortcut.title, + command: shortcut.command, + args: shortcut.arguments, + }; + })); const choice = await window.showQuickPick(items); if (!choice) { diff --git a/src/plugin.ts b/src/plugin.ts index 2ba87b479..d35dcdaaf 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -8,6 +8,46 @@ import { extensions } from 'vscode'; export let existingExtensions: Array = []; export let buildFilePatterns: Array = []; +let javaShortcuts: Array | undefined; +export interface IJavaShortcut { + title: string; + command: string; + arguments?: any[]; +} +export function getShortcuts(): Array { + if (javaShortcuts === undefined) { + javaShortcuts = []; + const selfOwnedShortcuts = getShortcutsRegistration(extensions.getExtension(EXTENSION_ID)); + if (selfOwnedShortcuts) { + javaShortcuts.push(...selfOwnedShortcuts); + } + for (const extension of extensions.all) { + if (extension.id === EXTENSION_ID) { + continue; + } + const shortcuts = getShortcutsRegistration(extension); + if (shortcuts) { + javaShortcuts.push(...shortcuts); + } + } + } + return javaShortcuts; +} + +function getShortcutsRegistration(extension: vscode.Extension): Array | undefined { + if (!extension) { + return undefined; + } + const contributesSection = extension.packageJSON['contributes']; + if (contributesSection) { + const shortcuts = contributesSection['javaShortcuts']; + if (shortcuts && Array.isArray(shortcuts) && shortcuts.length) { + return shortcuts; + } + } + return undefined; +} + export function collectJavaExtensions(extensions: readonly vscode.Extension[]): string[] { const result = []; if (extensions && extensions.length) { @@ -123,4 +163,6 @@ export interface IBuildTool { function isValidBuildTypeConfiguration(buildType: IBuildTool): boolean { return !!buildType.displayName && !!buildType.buildFileNames; -} \ No newline at end of file +} + +const EXTENSION_ID = 'redhat.java';