Skip to content

Commit 93e0a42

Browse files
authored
Add contribution point for java shortcuts (#3546)
Signed-off-by: Sheng Chen <[email protected]>
1 parent d588794 commit 93e0a42

File tree

4 files changed

+87
-13
lines changed

4 files changed

+87
-13
lines changed

package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,21 @@
8383
"buildFileNames": ["build.gradle", "settings.gradle", "build.gradle.kts", "settings.gradle.kts"]
8484
}
8585
],
86+
"javaShortcuts": [
87+
{
88+
"title": "$(settings-gear) Open Java Settings",
89+
"command": "workbench.action.openSettings",
90+
"arguments": ["java"]
91+
},
92+
{
93+
"title": "$(output) Open Logs",
94+
"command": "java.open.logs"
95+
},
96+
{
97+
"title": "$(trash) Clean Workspace Cache...",
98+
"command": "java.clean.workspace"
99+
}
100+
],
86101
"semanticTokenTypes": [
87102
{
88103
"id": "annotation",

schemas/package.schema.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,27 @@
4141
}
4242
}
4343
}
44+
},
45+
"javaShortcuts": {
46+
"type": "array",
47+
"description": "Shortcuts to be listed when clicking server status bar item.",
48+
"items": {
49+
"type": "object",
50+
"properties": {
51+
"title": {
52+
"description": "The title of the quick pick item.",
53+
"type": "string"
54+
},
55+
"command": {
56+
"description": "The command to be executed when the quick pick is selected.",
57+
"type": "string"
58+
},
59+
"arguments": {
60+
"description": "The arguments to be passed to the command.",
61+
"type": "array"
62+
}
63+
}
64+
}
4465
}
4566
}
4667
}

src/extension.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { initializeLogFile, logger } from './log';
1919
import { cleanupLombokCache } from "./lombokSupport";
2020
import { markdownPreviewProvider } from "./markdownPreviewProvider";
2121
import { OutputInfoCollector } from './outputInfoCollector';
22-
import { collectJavaExtensions, getBundlesToReload, isContributedPartUpdated } from './plugin';
22+
import { collectJavaExtensions, getBundlesToReload, getShortcuts, IJavaShortcut, isContributedPartUpdated } from './plugin';
2323
import { registerClientProviders } from './providerDispatcher';
2424
import { initialize as initializeRecommendation } from './recommendation';
2525
import * as requirements from './requirements';
@@ -364,17 +364,13 @@ export async function activate(context: ExtensionContext): Promise<ExtensionAPI>
364364
commands.executeCommand(Commands.SHOW_SERVER_TASK_STATUS, true);
365365
}
366366

367-
items.push({
368-
label: CommandTitle.OPEN_JAVA_SETTINGS,
369-
command: "workbench.action.openSettings",
370-
args: ["java"],
371-
}, {
372-
label: CommandTitle.OPEN_LOGS,
373-
command: Commands.OPEN_LOGS,
374-
}, {
375-
label: CommandTitle.CLEAN_WORKSPACE_CACHE,
376-
command: Commands.CLEAN_WORKSPACE
377-
});
367+
items.push(...getShortcuts().map((shortcut: IJavaShortcut) => {
368+
return {
369+
label: shortcut.title,
370+
command: shortcut.command,
371+
args: shortcut.arguments,
372+
};
373+
}));
378374

379375
const choice = await window.showQuickPick(items);
380376
if (!choice) {

src/plugin.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,46 @@ import { extensions } from 'vscode';
88
export let existingExtensions: Array<string> = [];
99
export let buildFilePatterns: Array<string> = [];
1010

11+
let javaShortcuts: Array<IJavaShortcut> | undefined;
12+
export interface IJavaShortcut {
13+
title: string;
14+
command: string;
15+
arguments?: any[];
16+
}
17+
export function getShortcuts(): Array<IJavaShortcut> {
18+
if (javaShortcuts === undefined) {
19+
javaShortcuts = [];
20+
const selfOwnedShortcuts = getShortcutsRegistration(extensions.getExtension(EXTENSION_ID));
21+
if (selfOwnedShortcuts) {
22+
javaShortcuts.push(...selfOwnedShortcuts);
23+
}
24+
for (const extension of extensions.all) {
25+
if (extension.id === EXTENSION_ID) {
26+
continue;
27+
}
28+
const shortcuts = getShortcutsRegistration(extension);
29+
if (shortcuts) {
30+
javaShortcuts.push(...shortcuts);
31+
}
32+
}
33+
}
34+
return javaShortcuts;
35+
}
36+
37+
function getShortcutsRegistration(extension: vscode.Extension<any>): Array<IJavaShortcut> | undefined {
38+
if (!extension) {
39+
return undefined;
40+
}
41+
const contributesSection = extension.packageJSON['contributes'];
42+
if (contributesSection) {
43+
const shortcuts = contributesSection['javaShortcuts'];
44+
if (shortcuts && Array.isArray(shortcuts) && shortcuts.length) {
45+
return shortcuts;
46+
}
47+
}
48+
return undefined;
49+
}
50+
1151
export function collectJavaExtensions(extensions: readonly vscode.Extension<any>[]): string[] {
1252
const result = [];
1353
if (extensions && extensions.length) {
@@ -123,4 +163,6 @@ export interface IBuildTool {
123163

124164
function isValidBuildTypeConfiguration(buildType: IBuildTool): boolean {
125165
return !!buildType.displayName && !!buildType.buildFileNames;
126-
}
166+
}
167+
168+
const EXTENSION_ID = 'redhat.java';

0 commit comments

Comments
 (0)