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

Add contribution point for java shortcuts #3546

Merged
merged 2 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}

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, {
ignoreFocusOut: true,
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';