Skip to content

Commit 214680c

Browse files
authored
feat: Add metadata for unmanaged folder (#479)
1 parent 9d3e62d commit 214680c

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed

jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/ProjectCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public static List<MainClassInfo> getMainClasses(List<Object> arguments, IProgre
199199
}
200200
}
201201
}
202-
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(searchRoots.toArray(IJavaElement[]::new));
202+
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(searchRoots.toArray(new IJavaElement[0]));
203203
SearchPattern pattern = SearchPattern.createPattern("main(String[]) void", IJavaSearchConstants.METHOD,
204204
IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);
205205
SearchRequestor requestor = new SearchRequestor() {

jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/model/PackageNode.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
package com.microsoft.jdtls.ext.core.model;
1313

1414
import java.net.URI;
15+
import java.util.ArrayList;
16+
import java.util.Arrays;
1517
import java.util.HashMap;
1618
import java.util.List;
1719
import java.util.Map;
@@ -43,13 +45,6 @@
4345
*/
4446
public class PackageNode {
4547

46-
/**
47-
* Nature Id for the IProject.
48-
*/
49-
private static final String NATURE_ID = "NatureId";
50-
51-
private static final String UNMANAGED_FOLDER_INNER_PATH = "UnmanagedFolderInnerPath";
52-
5348
public static final String K_TYPE_KIND = "TypeKind";
5449

5550
/**
@@ -67,15 +62,26 @@ public class PackageNode {
6762
*/
6863
public static final int K_ENUM = 3;
6964

65+
public static final String REFERENCED_LIBRARIES_PATH = "REFERENCED_LIBRARIES_PATH";
7066
private static final String REFERENCED_LIBRARIES_CONTAINER_NAME = "Referenced Libraries";
7167
private static final String IMMUTABLE_REFERENCED_LIBRARIES_CONTAINER_NAME = "Referenced Libraries (Read-only)";
72-
73-
public static final String REFERENCED_LIBRARIES_PATH = "REFERENCED_LIBRARIES_PATH";
7468
public static final ContainerNode REFERENCED_LIBRARIES_CONTAINER = new ContainerNode(REFERENCED_LIBRARIES_CONTAINER_NAME, REFERENCED_LIBRARIES_PATH,
7569
NodeKind.CONTAINER, IClasspathEntry.CPE_CONTAINER);
7670
public static final ContainerNode IMMUTABLE_REFERENCED_LIBRARIES_CONTAINER = new ContainerNode(IMMUTABLE_REFERENCED_LIBRARIES_CONTAINER_NAME,
7771
REFERENCED_LIBRARIES_PATH, NodeKind.CONTAINER, IClasspathEntry.CPE_CONTAINER);
7872

73+
/**
74+
* Nature Id for the IProject.
75+
*/
76+
private static final String NATURE_ID = "NatureId";
77+
78+
private static final String UNMANAGED_FOLDER_INNER_PATH = "UnmanagedFolderInnerPath";
79+
80+
/**
81+
* Nature Id for the unmanaged folder.
82+
*/
83+
private static final String UNMANAGED_FOLDER_NATURE_ID = "org.eclipse.jdt.ls.core.unmanagedFolder";
84+
7985
/**
8086
* The name of the PackageNode.
8187
*/
@@ -158,10 +164,12 @@ public static PackageNode createNodeForProject(IJavaElement javaElement) {
158164
PackageNode projectNode = new PackageNode(proj.getName(), proj.getFullPath().toPortableString(), NodeKind.PROJECT);
159165
projectNode.setUri(ProjectUtils.getProjectRealFolder(proj).toFile().toURI().toString());
160166
try {
161-
projectNode.setMetaDataValue(NATURE_ID, proj.getDescription().getNatureIds());
167+
List<String> natureIds = new ArrayList<>(Arrays.asList(proj.getDescription().getNatureIds()));
162168
if (!ProjectUtils.isVisibleProject(proj)) {
169+
natureIds.add(UNMANAGED_FOLDER_NATURE_ID);
163170
projectNode.setMetaDataValue(UNMANAGED_FOLDER_INNER_PATH, proj.getLocationURI().toString());
164171
}
172+
projectNode.setMetaDataValue(NATURE_ID, natureIds);
165173
} catch (CoreException e) {
166174
// do nothing
167175
}

src/views/projectNode.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ function getProjectType(natureId: string): string {
152152
return ReadableNature.Maven;
153153
case NatureId.Gradle:
154154
return ReadableNature.Gradle;
155+
case NatureId.UnmanagedFolder:
156+
return ReadableNature.UnmanagedFolder;
155157
default:
156158
return "";
157159
}
@@ -160,12 +162,14 @@ function getProjectType(natureId: string): string {
160162
enum NatureId {
161163
Maven = "org.eclipse.m2e.core.maven2Nature",
162164
Gradle = "org.eclipse.buildship.core.gradleprojectnature",
165+
UnmanagedFolder = "org.eclipse.jdt.ls.core.unmanagedFolder",
163166
Java = "org.eclipse.jdt.core.javanature",
164167
}
165168

166169
enum ReadableNature {
167170
Maven = "maven",
168171
Gradle = "gradle",
172+
UnmanagedFolder = "unmanagedFolder",
169173
Java = "java",
170174
}
171175

test/suite/contextValue.test.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ suite("Context Value Tests", () => {
2828
assert.ok(/java:project(?=.*?\b\+java\b)(?=.*?\b\+gradle\b)(?=.*?\b\+uri\b)/.test((await gradleProject.getTreeItem()).contextValue || ""));
2929
});
3030

31+
test("test unmanaged folder node", async function() {
32+
assert.ok(/java:project(?=.*?\b\+java\b)(?=.*?\b\+unmanagedFolder\b)(?=.*?\b\+uri\b)/
33+
.test((await unmanagedFolder.getTreeItem()).contextValue || ""));
34+
});
35+
3136
test("test JRE container node", async function() {
3237
assert.ok(/java:container(?=.*?\b\+jre\b)(?=.*?\b\+uri\b)/.test((await jreContainer.getTreeItem()).contextValue || ""));
3338
});
@@ -70,7 +75,7 @@ suite("Context Value Tests", () => {
7075
assert.ok(/java:package(?=.*?\b\+source\b)(?=.*?\b\+uri\b)/.test((await sourcePackage.getTreeItem()).contextValue || ""));
7176
});
7277

73-
test("test source package node", async function() {
78+
test("test source(test) package node", async function() {
7479
assert.ok(/java:package(?=.*?\b\+source\b)(?=.*?\b\+test\b)(?=.*?\b\+uri\b)/
7580
.test((await testSourcePackage.getTreeItem()).contextValue || ""));
7681
});
@@ -129,6 +134,15 @@ const gradleProject: ProjectNode = new ProjectNode({
129134
},
130135
}, workspace);
131136

137+
const unmanagedFolder: ProjectNode = new ProjectNode({
138+
name: "unmanagedFolder",
139+
uri: Uri.file(__dirname).toString(),
140+
kind: NodeKind.Project,
141+
metaData: {
142+
NatureId: ["org.eclipse.jdt.core.javanature", "org.eclipse.jdt.ls.core.unmanagedFolder"],
143+
},
144+
}, workspace);
145+
132146
const jreContainer: ContainerNode = new ContainerNode({
133147
name: "jreContainer",
134148
uri: Uri.file(__dirname).toString(),

0 commit comments

Comments
 (0)