Skip to content

Commit cf6a5a2

Browse files
authored
fix: Referenced Libraries container should be immutable for build tool projects (#826)
Signed-off-by: Sheng Chen <sheche@microsoft.com>
1 parent d7b002d commit cf6a5a2

File tree

5 files changed

+8
-12
lines changed

5 files changed

+8
-12
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,8 @@ private static List<PackageNode> getProjectChildren(PackageParams query, IProgre
303303
List<PackageNode> result = visitor.getNodes();
304304

305305
// Invisible project will always have the referenced libraries entry
306-
if (!ProjectUtils.isVisibleProject(project)) {
306+
if (!ProjectUtils.isVisibleProject(project) || hasReferencedLibraries) {
307307
result.add(PackageNode.REFERENCED_LIBRARIES_CONTAINER);
308-
} else if (hasReferencedLibraries) {
309-
result.add(PackageNode.IMMUTABLE_REFERENCED_LIBRARIES_CONTAINER);
310308
}
311309
return result;
312310
}
@@ -589,7 +587,7 @@ public static IProject getProject(String projectUri) {
589587
}
590588

591589
// This must be an invisible project.
592-
// There might be more than one way to access it, but all containers should link to the same project.
590+
// There might be more than one way to access it, but all containers should link to the same project.
593591
return containers[0].getProject();
594592
}
595593
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,9 @@ public class PackageNode {
6969

7070
public static final String REFERENCED_LIBRARIES_PATH = "REFERENCED_LIBRARIES_PATH";
7171
private static final String REFERENCED_LIBRARIES_CONTAINER_NAME = "Referenced Libraries";
72-
private static final String IMMUTABLE_REFERENCED_LIBRARIES_CONTAINER_NAME = "Referenced Libraries (Read-only)";
7372
public static final ContainerNode REFERENCED_LIBRARIES_CONTAINER = new ContainerNode(
7473
REFERENCED_LIBRARIES_CONTAINER_NAME, REFERENCED_LIBRARIES_PATH,
7574
NodeKind.CONTAINER, IClasspathEntry.CPE_CONTAINER);
76-
public static final ContainerNode IMMUTABLE_REFERENCED_LIBRARIES_CONTAINER = new ContainerNode(
77-
IMMUTABLE_REFERENCED_LIBRARIES_CONTAINER_NAME,
78-
REFERENCED_LIBRARIES_PATH, NodeKind.CONTAINER, IClasspathEntry.CPE_CONTAINER);
7975

8076
/**
8177
* Nature Id for the IProject.

src/views/containerNode.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export class ContainerNode extends DataNode {
2727
return ContainerType.Maven;
2828
} else if (containerPath.startsWith(ContainerPath.Gradle)) {
2929
return ContainerType.Gradle;
30-
} else if (containerPath.startsWith(ContainerPath.ReferencedLibrary)) {
30+
} else if (containerPath.startsWith(ContainerPath.ReferencedLibrary) && this._project.isUnmanagedFolder()) {
31+
// currently, we only support editing referenced libraries in unmanaged folders
3132
return ContainerType.ReferencedLibrary;
3233
}
3334
return ContainerType.Unknown;

src/views/packageRootNode.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ export class PackageRootNode extends DataNode {
5959
if (data.entryKind === PackageRootKind.K_BINARY) {
6060
contextValue = Explorer.ContextValueType.Jar;
6161
const parent = <ContainerNode>this.getParent();
62-
if (parent.path?.startsWith("REFERENCED_LIBRARIES_PATH")) {
62+
// currently, we only support editing referenced libraries in unmanaged folders
63+
if (parent.path?.startsWith("REFERENCED_LIBRARIES_PATH") && this._project.isUnmanagedFolder()) {
6364
contextValue += "+referencedLibrary";
6465
}
6566
return contextValue;

test/suite/contextValue.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ const referencedLibrariesContainer: ContainerNode = new ContainerNode({
182182
uri: Uri.file(__dirname).toString(),
183183
kind: NodeKind.Container,
184184
path: "REFERENCED_LIBRARIES_PATH",
185-
}, mavenProject, mavenProject);
185+
}, mavenProject, unmanagedFolder);
186186

187187
const sourceRoot: PackageRootNode = new PackageRootNode({
188188
name: "src/main/java",
@@ -220,7 +220,7 @@ const referencedLibraryJar: PackageRootNode = new PackageRootNode({
220220
uri: Uri.file(__dirname).toString(),
221221
kind: NodeKind.PackageRoot,
222222
entryKind: PackageRootKind.K_BINARY,
223-
} as INodeData, referencedLibrariesContainer, mavenProject);
223+
} as INodeData, referencedLibrariesContainer, unmanagedFolder);
224224

225225
const sourcePackage: PackageNode = new PackageNode({
226226
name: "com.microsoft.java",

0 commit comments

Comments
 (0)