Skip to content

Commit b3d964b

Browse files
fvclausjdneo
andauthored
Fixes java.getPackageData for modules with long name (#791)
Signed-off-by: Frederik Claus <f.v.claus@googlemail.com> Co-authored-by: Sheng Chen <sheche@microsoft.com>
1 parent 0ec45cc commit b3d964b

File tree

20 files changed

+538
-240
lines changed

20 files changed

+538
-240
lines changed

.vscode/launch.json

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,36 @@
9292
"outFiles": [ "${workspaceFolder}/dist/**/*.js" ],
9393
"preLaunchTask": "npm: compile"
9494
},
95+
{
96+
"name": "Extension Tests - Multi Module Project",
97+
"type": "extensionHost",
98+
"request": "launch",
99+
"runtimeExecutable": "${execPath}",
100+
"args": [
101+
"${workspaceFolder}/test/multi-module/",
102+
"--extensionDevelopmentPath=${workspaceFolder}",
103+
"--extensionTestsPath=${workspaceFolder}/dist/test/multi-module-suite/index"
104+
],
105+
"sourceMaps": true,
106+
"outFiles": [ "${workspaceFolder}/dist/**/*.js" ],
107+
"preLaunchTask": "npm: compile"
108+
},
95109
{
96110
"name": "Debug UI Command Tests",
97111
"type": "node",
98112
"request": "launch",
99113
"program": "${workspaceFolder}/node_modules/vscode-extension-tester/out/cli.js",
100114
"args": [
101115
"setup-and-run",
116+
// If not set, will use the current version of vscode. Find a way not to hardcode this value.
117+
"--code_version=1.77.0",
102118
"${workspaceFolder}/dist/test/ui/command.test.js",
103119
],
120+
// To debug the test code, you must set --mode=development inside the vscode:prepublish task. Find a better way to do this.
121+
"sourceMaps": true,
122+
"outFiles": [ "${workspaceFolder}/dist/**/*.js" ],
104123
"console": "integratedTerminal",
105-
"internalConsoleOptions": "neverOpen",
106-
"preLaunchTask": "npm: compile"
124+
// No need to compile the code, vscode:prepublish task that compiles the code is run by vscode-extension-tester
107125
},
108126
]
109127
}

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

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
import java.util.ArrayList;
1515
import java.util.Arrays;
1616
import java.util.Collections;
17-
import java.util.Comparator;
1817
import java.util.HashMap;
1918
import java.util.LinkedList;
2019
import java.util.List;
2120
import java.util.Map;
21+
import java.util.Optional;
2222
import java.util.Set;
2323
import java.util.function.BiFunction;
2424
import java.util.stream.Collectors;
@@ -577,26 +577,21 @@ private static Object[] findJarDirectoryChildren(JarEntryDirectory directory, St
577577

578578
public static IProject getProject(String projectUri) {
579579
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
580-
IContainer[] containers = root.findContainersForLocationURI(JDTUtils.toURI(projectUri));
580+
URI uri = JDTUtils.toURI(projectUri);
581+
IContainer[] containers = root.findContainersForLocationURI(uri);
581582

582-
if (containers.length == 0) {
583-
return null;
584-
}
585-
586-
// For multi-module scenario, findContainersForLocationURI API may return a container array,
587-
// put the result from the nearest project in front.
588-
Arrays.sort(containers, (Comparator<IContainer>) (IContainer a, IContainer b) -> {
589-
return a.getFullPath().toPortableString().length() - b.getFullPath().toPortableString().length();
590-
});
591-
592-
for (IContainer container : containers) {
593-
IProject project = container.getProject();
594-
if (!project.exists()) {
595-
return null;
583+
Optional<IContainer> maybeProject = Arrays.stream(containers).filter(container -> container instanceof IProject).findFirst();
584+
if (maybeProject.isPresent()) {
585+
return (IProject) maybeProject.get();
586+
} else {
587+
if (containers.length == 0) {
588+
throw new IllegalArgumentException(String.format("Did not find container for URI %s", projectUri));
596589
}
597-
return project;
590+
591+
// 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.
593+
return containers[0].getProject();
598594
}
599-
return null;
600595
}
601596

602597
public static IJavaProject getJavaProject(String projectUri) {

0 commit comments

Comments
 (0)