Skip to content

Commit

Permalink
Add contribution point for java shortcuts (#3546)
Browse files Browse the repository at this point in the history
Signed-off-by: Sheng Chen <[email protected]>
  • Loading branch information
jdneo authored Apr 1, 2024
1 parent d588794 commit 93e0a42
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 13 deletions.
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 21 additions & 0 deletions schemas/package.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
}
}
Expand Down
20 changes: 8 additions & 12 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -364,17 +364,13 @@ export async function activate(context: ExtensionContext): Promise<ExtensionAPI>
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) {
Expand Down
44 changes: 43 additions & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,46 @@ import { extensions } from 'vscode';
export let existingExtensions: Array<string> = [];
export let buildFilePatterns: Array<string> = [];

let javaShortcuts: Array<IJavaShortcut> | undefined;
export interface IJavaShortcut {
title: string;
command: string;
arguments?: any[];
}
export function getShortcuts(): Array<IJavaShortcut> {
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<any>): Array<IJavaShortcut> | 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<any>[]): string[] {
const result = [];
if (extensions && extensions.length) {
Expand Down Expand Up @@ -123,4 +163,6 @@ export interface IBuildTool {

function isValidBuildTypeConfiguration(buildType: IBuildTool): boolean {
return !!buildType.displayName && !!buildType.buildFileNames;
}
}

const EXTENSION_ID = 'redhat.java';

0 comments on commit 93e0a42

Please sign in to comment.