diff --git a/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/ProjectCommand.java b/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/ProjectCommand.java index e4ebaae4..00378758 100644 --- a/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/ProjectCommand.java +++ b/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/ProjectCommand.java @@ -14,7 +14,6 @@ import java.io.File; import java.io.FileOutputStream; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Objects; @@ -34,6 +33,7 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; +import org.apache.commons.io.FilenameUtils; import org.eclipse.core.resources.IFile; import org.eclipse.jdt.core.search.IJavaSearchScope; import org.eclipse.jdt.core.search.SearchEngine; @@ -56,7 +56,6 @@ import org.eclipse.jdt.ls.core.internal.managers.UpdateClasspathJob; import org.eclipse.jdt.ls.core.internal.preferences.Preferences.ReferencedLibraries; -import com.microsoft.jdtls.ext.core.model.NodeKind; import com.microsoft.jdtls.ext.core.model.PackageNode; import org.eclipse.lsp4j.jsonrpc.json.adapters.CollectionTypeAdapter; import org.eclipse.lsp4j.jsonrpc.json.adapters.EnumTypeAdapter; @@ -90,15 +89,15 @@ public static List listProjects(List arguments, IProgressMo IProject[] projects = getWorkspaceRoot().getProjects(); ArrayList children = new ArrayList<>(); - List paths = Arrays.asList(workspacePath); for (IProject project : projects) { - if (!ProjectUtils.isJavaProject(project)) { + if (!project.isAccessible() || !ProjectUtils.isJavaProject(project) || Objects.equals(project, JavaLanguageServerPlugin.getProjectsManager().getDefaultProject())) { continue; } - if (project.exists() && (ResourceUtils.isContainedIn(project.getLocation(), paths) || Objects.equals(project.getName(), invisibleProjectName))) { - PackageNode projectNode = PackageNode.createNodeForProject(JavaCore.create(project)); - children.add(projectNode); + PackageNode projectNode = PackageNode.createNodeForProject(JavaCore.create(project)); + if (Objects.equals(project.getName(), invisibleProjectName)) { + projectNode.setDisplayName(FilenameUtils.getBaseName(workspaceUri)); } + children.add(projectNode); } return children; } diff --git a/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/model/PackageNode.java b/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/model/PackageNode.java index f53f20dd..16eae609 100644 --- a/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/model/PackageNode.java +++ b/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/model/PackageNode.java @@ -73,6 +73,11 @@ public class PackageNode { */ private String name; + /** + * The display name of the node + */ + private String displayName; + /** * The module name of the PackageNode for Java 9 and above */ @@ -275,6 +280,10 @@ public String getName() { return name; } + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + public void setModuleName(String moduleName) { this.moduleName = moduleName; } diff --git a/src/java/nodeData.ts b/src/java/nodeData.ts index f896d608..f4d884eb 100644 --- a/src/java/nodeData.ts +++ b/src/java/nodeData.ts @@ -19,6 +19,7 @@ export enum TypeKind { } export interface INodeData { + displayName?: string; name: string; moduleName?: string; path?: string; diff --git a/src/views/dataNode.ts b/src/views/dataNode.ts index 6fc4f057..b150e2bc 100644 --- a/src/views/dataNode.ts +++ b/src/views/dataNode.ts @@ -13,7 +13,10 @@ export abstract class DataNode extends ExplorerNode { public getTreeItem(): TreeItem | Promise { if (this._nodeData) { - const item = new TreeItem(this._nodeData.name, this.hasChildren() ? TreeItemCollapsibleState.Collapsed : TreeItemCollapsibleState.None); + const item = new TreeItem( + this._nodeData.displayName || this._nodeData.name, + this.hasChildren() ? TreeItemCollapsibleState.Collapsed : TreeItemCollapsibleState.None, + ); item.description = this.description; item.iconPath = this.iconPath; item.command = this.command;