Skip to content

Commit

Permalink
feat: Support showing Gradle sub-menu for BSP Gradle projects (#786)
Browse files Browse the repository at this point in the history
Signed-off-by: Sheng Chen <[email protected]>
  • Loading branch information
jdneo authored Aug 29, 2023
1 parent 903b88c commit 2ba3227
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -617,12 +617,12 @@
},
{
"submenu": "javaProject.maven",
"when": "view == javaProjectExplorer && viewItem =~ /java:project(?=.*?\\b\\+uri\\b)(?=.*?\\b\\+(maven)\\b)/",
"when": "view == javaProjectExplorer && viewItem =~ /java:project(?=.*?\\b\\+uri\\b)(?=.*?\\b\\+maven\\b)/",
"group": "9_configuration@10"
},
{
"submenu": "javaProject.gradle",
"when": "view == javaProjectExplorer && viewItem =~ /java:project(?=.*?\\b\\+uri\\b)(?=.*?\\b\\+(gradle)\\b)/",
"when": "view == javaProjectExplorer && viewItem =~ /java:project(?=.*?\\b\\+uri\\b)(?=.*?\\b\\+(?:bsp-)?gradle\\b)/",
"group": "9_configuration@10"
}
],
Expand Down
10 changes: 5 additions & 5 deletions src/views/projectNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import { NodeFactory } from "./nodeFactory";

export class ProjectNode extends DataNode {

constructor(nodeData: INodeData, parent?: DataNode) {
super(nodeData, parent);
}

public async revealPaths(paths: INodeData[]): Promise<DataNode | undefined> {
if (!this.uri) {
return undefined;
Expand Down Expand Up @@ -65,7 +61,7 @@ export class ProjectNode extends DataNode {
protected createChildNodeList(): ExplorerNode[] {
const result: (ExplorerNode | undefined)[] = [];
const packageData: any[] = [];
if (this.nodeData.children && this.nodeData.children.length) {
if (this.nodeData.children?.length) {
this.nodeData.children.forEach((nodeData) => {
if (nodeData.kind === NodeKind.Package) {
packageData.push(nodeData);
Expand Down Expand Up @@ -123,6 +119,8 @@ function getProjectType(natureId: string): string {
return ReadableNature.Maven;
case NatureId.Gradle:
return ReadableNature.Gradle;
case NatureId.BspGradle:
return ReadableNature.BspGradle;
case NatureId.UnmanagedFolder:
return ReadableNature.UnmanagedFolder;
default:
Expand All @@ -133,13 +131,15 @@ function getProjectType(natureId: string): string {
enum NatureId {
Maven = "org.eclipse.m2e.core.maven2Nature",
Gradle = "org.eclipse.buildship.core.gradleprojectnature",
BspGradle = "com.microsoft.gradle.bs.importer.GradleBuildServerProjectNature",
UnmanagedFolder = "org.eclipse.jdt.ls.core.unmanagedFolder",
Java = "org.eclipse.jdt.core.javanature",
}

enum ReadableNature {
Maven = "maven",
Gradle = "gradle",
BspGradle = "bsp-gradle",
UnmanagedFolder = "unmanagedFolder",
Java = "java",
}
Expand Down
13 changes: 13 additions & 0 deletions test/suite/contextValue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ suite("Context Value Tests", () => {
assert.ok(/java:project(?=.*?\b\+java\b)(?=.*?\b\+gradle\b)(?=.*?\b\+uri\b)/.test((await gradleProject.getTreeItem()).contextValue || ""));
});

test("test BSP Gradle project node", async function() {
assert.ok(/java:project(?=.*?\b\+java\b)(?=.*?\b\+bsp-gradle\b)(?=.*?\b\+uri\b)/.test((await bspGradleProject.getTreeItem()).contextValue || ""));
});

test("test unmanaged folder node", async function() {
assert.ok(/java:project(?=.*?\b\+java\b)(?=.*?\b\+unmanagedFolder\b)(?=.*?\b\+uri\b)/
.test((await unmanagedFolder.getTreeItem()).contextValue || ""));
Expand Down Expand Up @@ -134,6 +138,15 @@ const gradleProject: ProjectNode = new ProjectNode({
},
}, workspace);

const bspGradleProject: ProjectNode = new ProjectNode({
name: "bspGradleProject",
uri: Uri.file(__dirname).toString(),
kind: NodeKind.Project,
metaData: {
NatureId: ["org.eclipse.jdt.core.javanature", "com.microsoft.gradle.bs.importer.GradleBuildServerProjectNature"],
},
}, workspace);

const unmanagedFolder: ProjectNode = new ProjectNode({
name: "unmanagedFolder",
uri: Uri.file(__dirname).toString(),
Expand Down

0 comments on commit 2ba3227

Please sign in to comment.