Skip to content

Commit 8f59095

Browse files
authored
feat: Add 'Build All' and 'Build Project' commands into context menu. (#663)
Signed-off-by: sheche <[email protected]>
1 parent a444949 commit 8f59095

File tree

5 files changed

+33
-3
lines changed

5 files changed

+33
-3
lines changed

package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@
8888
"command": "java.project.update",
8989
"title": "%contributes.commands.java.project.update%"
9090
},
91+
{
92+
"command": "java.project.rebuild",
93+
"title": "%contributes.commands.java.project.rebuild%"
94+
},
9195
{
9296
"command": "java.view.package.revealInProjectExplorer",
9397
"title": "%contributes.commands.java.view.package.revealInProjectExplorer%",
@@ -358,6 +362,10 @@
358362
"command": "java.project.update",
359363
"when": "false"
360364
},
365+
{
366+
"command": "java.project.rebuild",
367+
"when": "false"
368+
},
361369
{
362370
"command": "java.view.package.revealInProjectExplorer",
363371
"when": "false"
@@ -480,6 +488,16 @@
480488
"when": "view == javaProjectExplorer && !explorerResourceMoveableToTrash && viewItem =~ /java:(file|type|folder)(?=.*?\\b\\+uri\\b)/",
481489
"group": "7_modification@20"
482490
},
491+
{
492+
"command": "java.project.build.workspace",
493+
"when": "view == javaProjectExplorer && viewItem =~ /java:project(?=.*?\\b\\+java\\b)(?=.*?\\b\\+uri\\b)/",
494+
"group":"8_execution@5"
495+
},
496+
{
497+
"command": "java.project.rebuild",
498+
"when": "view == javaProjectExplorer && viewItem =~ /java:project(?=.*?\\b\\+java\\b)(?=.*?\\b\\+uri\\b)/",
499+
"group": "8_execution@6"
500+
},
483501
{
484502
"command": "java.view.package.newJavaClass",
485503
"when": "view == javaProjectExplorer && viewItem =~ /java:(package|packageRoot)(?=.*?\\b\\+source\\b)(?=.*?\\b\\+uri\\b)/",

package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
"contributes.commands.java.project.addLibraryFolders": "Add Library Folders to Project Classpath...",
66
"contributes.commands.java.project.removeLibrary": "Remove from Project Classpath",
77
"contributes.commands.java.view.package.refresh": "Refresh",
8-
"contributes.commands.java.project.build.workspace": "Rebuild Workspace",
8+
"contributes.commands.java.project.build.workspace": "Rebuild All",
99
"contributes.commands.java.project.clean.workspace": "Clean Workspace",
1010
"contributes.commands.java.project.update": "Update Project",
11+
"contributes.commands.java.project.rebuild": "Rebuild Project",
1112
"contributes.commands.java.view.package.revealInProjectExplorer": "Reveal in Java Project Explorer",
1213
"contributes.commands.java.view.package.changeToFlatPackageView":"Flat View",
1314
"contributes.commands.java.view.package.changeToHierarchicalPackageView":"Hierarchical View",

package.nls.zh.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
"contributes.commands.java.project.addLibraryFolders": "添加文件夹至项目 Classpath...",
66
"contributes.commands.java.project.removeLibrary": "从项目 Classpath 中移除",
77
"contributes.commands.java.view.package.refresh": "刷新",
8-
"contributes.commands.java.project.build.workspace": "重新构建工作空间",
8+
"contributes.commands.java.project.build.workspace": "重新构建所有项目",
99
"contributes.commands.java.project.clean.workspace": "清理工作空间",
1010
"contributes.commands.java.project.update": "更新项目",
11+
"contributes.commands.java.project.rebuild": "重新构建项目",
1112
"contributes.commands.java.view.package.revealInProjectExplorer": "在 Java 项目视图中显示",
1213
"contributes.commands.java.view.package.changeToFlatPackageView":"平行显示",
1314
"contributes.commands.java.view.package.changeToHierarchicalPackageView":"层级显示",

src/commands.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ export namespace Commands {
6464

6565
export const JAVA_PROJECT_UPDATE = "java.project.update";
6666

67+
export const JAVA_PROJECT_REBUILD = "java.project.rebuild";
68+
6769
export const JAVA_PROJECT_EXPLORER_FOCUS = "javaProjectExplorer.focus";
6870

6971
export const JAVA_PROJECT_LIST = "java.project.list";

src/views/dependencyDataProvider.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
commands, Event, EventEmitter, ExtensionContext, ProviderResult,
77
RelativePattern, TreeDataProvider, TreeItem, Uri, window, workspace,
88
} from "vscode";
9-
import { instrumentOperationAsVsCodeCommand } from "vscode-extension-telemetry-wrapper";
9+
import { instrumentOperationAsVsCodeCommand, sendError } from "vscode-extension-telemetry-wrapper";
1010
import { contextManager } from "../../extension.bundle";
1111
import { Commands } from "../commands";
1212
import { Context } from "../constants";
@@ -69,6 +69,14 @@ export class DependencyDataProvider implements TreeDataProvider<ExplorerNode> {
6969
commands.executeCommand(Commands.JAVA_PROJECT_CONFIGURATION_UPDATE, uris[0]);
7070
}
7171
}));
72+
context.subscriptions.push(instrumentOperationAsVsCodeCommand(Commands.JAVA_PROJECT_REBUILD, async (node: INodeData) => {
73+
if (!node.uri) {
74+
sendError(new Error("Uri not available when building project"));
75+
window.showErrorMessage("The URI of the project is not available, you can try to trigger the command 'Java: Rebuild Projects' from Command Palette.");
76+
return;
77+
}
78+
commands.executeCommand(Commands.BUILD_PROJECT, Uri.parse(node.uri), true);
79+
}));
7280

7381
Settings.registerConfigurationListener((updatedConfig, oldConfig) => {
7482
if (updatedConfig.refreshDelay !== oldConfig.refreshDelay) {

0 commit comments

Comments
 (0)