From 2ba3227264d9c0967d409bebac9bbf9fb07e9d67 Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Tue, 29 Aug 2023 14:58:41 +0800 Subject: [PATCH] feat: Support showing Gradle sub-menu for BSP Gradle projects (#786) Signed-off-by: Sheng Chen --- package.json | 4 ++-- src/views/projectNode.ts | 10 +++++----- test/suite/contextValue.test.ts | 13 +++++++++++++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index f2a82249..7e1aaf66 100644 --- a/package.json +++ b/package.json @@ -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" } ], diff --git a/src/views/projectNode.ts b/src/views/projectNode.ts index a19ace6d..2d127fb0 100644 --- a/src/views/projectNode.ts +++ b/src/views/projectNode.ts @@ -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 { if (!this.uri) { return undefined; @@ -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); @@ -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: @@ -133,6 +131,7 @@ 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", } @@ -140,6 +139,7 @@ enum NatureId { enum ReadableNature { Maven = "maven", Gradle = "gradle", + BspGradle = "bsp-gradle", UnmanagedFolder = "unmanagedFolder", Java = "java", } diff --git a/test/suite/contextValue.test.ts b/test/suite/contextValue.test.ts index 9fa1e1d5..3cb04022 100644 --- a/test/suite/contextValue.test.ts +++ b/test/suite/contextValue.test.ts @@ -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 || "")); @@ -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(),