Skip to content

Commit 379e101

Browse files
authored
fix: Cannot expand for multi-module project (#425)
1 parent b823212 commit 379e101

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.ArrayList;
1515
import java.util.Arrays;
1616
import java.util.Collections;
17+
import java.util.Comparator;
1718
import java.util.HashMap;
1819
import java.util.List;
1920
import java.util.Map;
@@ -581,6 +582,12 @@ public static IJavaProject getJavaProject(String projectUri) {
581582
return null;
582583
}
583584

585+
// For multi-module scenario, findContainersForLocationURI API may return a container array,
586+
// need put the result from the nearest project in front.
587+
Arrays.sort(containers, (Comparator<IContainer>) (IContainer a, IContainer b) -> {
588+
return a.getFullPath().toPortableString().length() - b.getFullPath().toPortableString().length();
589+
});
590+
584591
for (IContainer container : containers) {
585592
IProject project = container.getProject();
586593
if (!project.exists()) {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ public void setMetaDataValue(String key, Object value) {
151151
}
152152

153153
public static PackageNode createNodeForProject(IJavaElement javaElement) {
154+
if (javaElement == null || javaElement.getJavaProject() == null) {
155+
return null;
156+
}
154157
IProject proj = javaElement.getJavaProject().getProject();
155158
PackageNode projectNode = new PackageNode(proj.getName(), proj.getFullPath().toPortableString(), NodeKind.PROJECT);
156159
projectNode.setUri(ProjectUtils.getProjectRealFolder(proj).toFile().toURI().toString());

0 commit comments

Comments
 (0)