Skip to content

Commit 2397d9e

Browse files
authored
bugfix: Can only modify the referenced libraries in invisible project (#227)
1 parent 20cf05b commit 2397d9e

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,11 @@ private static List<PackageNode> getContainers(PackageParams query, IProgressMon
247247
.collect(Collectors.toList());
248248
boolean isReferencedLibrariesExist = Arrays.stream(references)
249249
.anyMatch(entry -> entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY || entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE);
250-
if (isReferencedLibrariesExist || !ProjectUtils.isVisibleProject(javaProject.getProject())) {
250+
// Invisble project will always have the referenced libraries entry
251+
if (!ProjectUtils.isVisibleProject(javaProject.getProject())) {
251252
result.add(PackageNode.REFERENCED_LIBRARIES_CONTAINER);
253+
} else if (isReferencedLibrariesExist) {
254+
result.add(PackageNode.IMMUTABLE_REFERENCED_LIBRARIES_CONTAINER);
252255
}
253256
return result;
254257
} catch (CoreException e) {
@@ -258,8 +261,6 @@ private static List<PackageNode> getContainers(PackageParams query, IProgressMon
258261
return Collections.emptyList();
259262
}
260263

261-
262-
263264
private static List<PackageNode> getPackageFragmentRoots(PackageParams query, IProgressMonitor pm) {
264265
ArrayList<PackageNode> children = new ArrayList<>();
265266
IJavaProject javaProject = getJavaProject(query.getProjectUri());

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

+3
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@
4040
*/
4141
public class PackageNode {
4242
private static final String REFERENCED_LIBRARIES_CONTAINER_NAME = "Referenced Libraries";
43+
private static final String IMMUTABLE_REFERENCED_LIBRARIES_CONTAINER_NAME = "Referenced Libraries (Read-only)";
4344

4445
public static final String REFERENCED_LIBRARIES_PATH = "REFERENCED_LIBRARIES_PATH";
4546
public static final String DEFAULT_PACKAGE_DISPLAYNAME = "(default package)";
4647
public static final ContainerNode REFERENCED_LIBRARIES_CONTAINER = new ContainerNode(REFERENCED_LIBRARIES_CONTAINER_NAME, REFERENCED_LIBRARIES_PATH,
4748
NodeKind.CONTAINER, IClasspathEntry.CPE_CONTAINER);
49+
public static final ContainerNode IMMUTABLE_REFERENCED_LIBRARIES_CONTAINER = new ContainerNode(IMMUTABLE_REFERENCED_LIBRARIES_CONTAINER_NAME, REFERENCED_LIBRARIES_PATH,
50+
NodeKind.CONTAINER, IClasspathEntry.CPE_CONTAINER);
4851

4952
/**
5053
* The name of the PackageNode

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -230,17 +230,17 @@
230230
},
231231
{
232232
"command": "java.project.addLibraries",
233-
"when": "view == javaDependencyExplorer && viewItem =~ /java:container\/referenced-libraries/",
233+
"when": "view == javaDependencyExplorer && viewItem =~ /java:container\/referenced-libraries$/",
234234
"group": "inline@0"
235235
},
236236
{
237237
"command": "java.project.removeLibrary",
238-
"when": "view == javaDependencyExplorer && viewItem =~ /java:jar\/referenced-libraries/",
238+
"when": "view == javaDependencyExplorer && viewItem =~ /java:jar\/referenced-libraries\\+uri$/",
239239
"group": "inline"
240240
},
241241
{
242242
"command": "java.project.refreshLibraries",
243-
"when": "view == javaDependencyExplorer && viewItem =~ /java:container\/referenced-libraries/",
243+
"when": "view == javaDependencyExplorer && viewItem =~ /java:container\/referenced-libraries$/",
244244
"group": "inline@1"
245245
}
246246
]

0 commit comments

Comments
 (0)