Skip to content

Commit a27b2ae

Browse files
authored
fix: Remove the limitation of only displaying invisible projects (#684)
- now, no matter where the projects are located, we will display all of them in Java Projects explorer. (The only exception is the default project). Signed-off-by: Sheng Chen <[email protected]>
1 parent 6c9d156 commit a27b2ae

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.io.FileOutputStream;
1919
import java.io.IOException;
2020
import java.util.ArrayList;
21-
import java.util.Collections;
2221
import java.util.HashSet;
2322
import java.util.List;
2423
import java.util.Objects;
@@ -59,6 +58,7 @@
5958
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
6059
import org.eclipse.jdt.ls.core.internal.ProjectUtils;
6160
import org.eclipse.jdt.ls.core.internal.ResourceUtils;
61+
import org.eclipse.jdt.ls.core.internal.managers.ProjectsManager;
6262
import org.eclipse.jdt.ls.core.internal.managers.UpdateClasspathJob;
6363
import org.eclipse.jdt.ls.core.internal.preferences.Preferences.ReferencedLibraries;
6464
import org.eclipse.lsp4j.jsonrpc.json.adapters.CollectionTypeAdapter;
@@ -94,24 +94,25 @@ private static class Classpath {
9494
public static List<PackageNode> listProjects(List<Object> arguments, IProgressMonitor monitor) {
9595
String workspaceUri = (String) arguments.get(0);
9696
IPath workspaceFolderPath = ResourceUtils.canonicalFilePathFromURI(workspaceUri);
97-
String invisibleProjectName = ProjectUtils.getWorkspaceInvisibleProjectName(workspaceFolderPath);
9897

99-
IProject[] projects = getWorkspaceRoot().getProjects();
98+
IJavaProject[] javaProjects = ProjectUtils.getJavaProjects();
10099
ArrayList<PackageNode> children = new ArrayList<>();
101-
List<IPath> paths = Collections.singletonList(workspaceFolderPath);
102-
for (IProject project : projects) {
103-
if (!project.isAccessible() || !ProjectUtils.isJavaProject(project)) {
100+
for (IJavaProject javaProject : javaProjects) {
101+
IProject project = javaProject.getProject();
102+
if (!project.isAccessible() || project.getLocation() == null) {
104103
continue;
105104
}
106-
// Ignore all the projects that's not contained in the workspace folder, except
107-
// for the invisible project.
108-
// This check is needed in multi-root scenario.
109-
if ((!ResourceUtils.isContainedIn(project.getLocation(), paths)
110-
&& !Objects.equals(project.getName(), invisibleProjectName))) {
105+
106+
// ignore default projects
107+
if (Objects.equals(project.getName(), ProjectsManager.DEFAULT_PROJECT_NAME)) {
111108
continue;
112109
}
110+
113111
PackageNode projectNode = PackageNode.createNodeForProject(JavaCore.create(project));
114-
if (Objects.equals(project.getName(), invisibleProjectName)) {
112+
113+
// set the folder name as the project name when the project location
114+
// is out of the workspace folder.
115+
if (!workspaceFolderPath.isPrefixOf(project.getLocation())) {
115116
projectNode.setDisplayName(workspaceFolderPath.lastSegment());
116117
}
117118
children.add(projectNode);

0 commit comments

Comments
 (0)