Skip to content

Commit ab59282

Browse files
authored
fix: Cannot show the content of a referenced jar (#376)
Signed-off-by: Sheng Chen <[email protected]>
1 parent 7021f1c commit ab59282

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ private static List<PackageNode> getPackageFragmentRoots(PackageParams query, IP
341341

342342
private static List<PackageNode> getPackages(PackageParams query, IProgressMonitor pm) {
343343
try {
344-
IPackageFragmentRoot packageRoot = (IPackageFragmentRoot) JavaCore.create(query.getHandlerIdentifier());
344+
IPackageFragmentRoot packageRoot = getPackageFragmentRootFromQuery(query);
345345
if (packageRoot == null) {
346346
throw new CoreException(
347347
new Status(IStatus.ERROR, JdtlsExtActivator.PLUGIN_ID, String.format("No package root found for %s", query.getPath())));
@@ -354,6 +354,25 @@ private static List<PackageNode> getPackages(PackageParams query, IProgressMonit
354354
return Collections.emptyList();
355355
}
356356

357+
private static IPackageFragmentRoot getPackageFragmentRootFromQuery(PackageParams query) {
358+
IPackageFragmentRoot packageRoot = (IPackageFragmentRoot) JavaCore.create(query.getHandlerIdentifier());
359+
if (packageRoot != null) {
360+
return packageRoot;
361+
}
362+
363+
// jar in Referenced Libraries must be constructed from path
364+
IJavaProject javaProject = getJavaProject(query.getProjectUri());
365+
if (javaProject != null) {
366+
try {
367+
packageRoot = javaProject.findPackageFragmentRoot(Path.fromPortableString(query.getRootPath()));
368+
} catch (JavaModelException e) {
369+
return null;
370+
}
371+
}
372+
373+
return packageRoot;
374+
}
375+
357376
private static List<PackageNode> getRootTypes(PackageParams query, IProgressMonitor pm) {
358377
try {
359378
IPackageFragment packageFragment = (IPackageFragment) JavaCore.create(query.getHandlerIdentifier());

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public class PackageParams {
2727

2828
private String handlerIdentifier;
2929

30+
private String rootPath;
31+
3032
public PackageParams() {
3133
}
3234

@@ -77,4 +79,12 @@ public void setHandlerIdentifier(String handlerIdentifier) {
7779
this.handlerIdentifier = handlerIdentifier;
7880
}
7981

82+
public String getRootPath() {
83+
return rootPath;
84+
}
85+
86+
public void setRootPath(String rootPath) {
87+
this.rootPath = rootPath;
88+
}
89+
8090
}

src/views/packageRootNode.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class PackageRootNode extends DataNode {
2525
return Jdtls.getPackageData({
2626
kind: NodeKind.PackageRoot,
2727
projectUri: this._project.nodeData.uri,
28+
rootPath: this.nodeData.path,
2829
handlerIdentifier: this.nodeData.handlerIdentifier,
2930
});
3031
}

0 commit comments

Comments
 (0)