Skip to content

Commit ea43694

Browse files
authored
Use folder name as the name of the invisible project (#312)
1 parent 03173b5 commit ea43694

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.io.File;
1515
import java.io.FileOutputStream;
1616
import java.util.ArrayList;
17-
import java.util.Arrays;
1817
import java.util.HashSet;
1918
import java.util.List;
2019
import java.util.Objects;
@@ -34,6 +33,7 @@
3433
import org.eclipse.core.runtime.IProgressMonitor;
3534
import org.eclipse.core.runtime.NullProgressMonitor;
3635
import org.eclipse.core.runtime.Path;
36+
import org.apache.commons.io.FilenameUtils;
3737
import org.eclipse.core.resources.IFile;
3838
import org.eclipse.jdt.core.search.IJavaSearchScope;
3939
import org.eclipse.jdt.core.search.SearchEngine;
@@ -56,7 +56,6 @@
5656
import org.eclipse.jdt.ls.core.internal.managers.UpdateClasspathJob;
5757
import org.eclipse.jdt.ls.core.internal.preferences.Preferences.ReferencedLibraries;
5858

59-
import com.microsoft.jdtls.ext.core.model.NodeKind;
6059
import com.microsoft.jdtls.ext.core.model.PackageNode;
6160
import org.eclipse.lsp4j.jsonrpc.json.adapters.CollectionTypeAdapter;
6261
import org.eclipse.lsp4j.jsonrpc.json.adapters.EnumTypeAdapter;
@@ -90,15 +89,15 @@ public static List<PackageNode> listProjects(List<Object> arguments, IProgressMo
9089

9190
IProject[] projects = getWorkspaceRoot().getProjects();
9291
ArrayList<PackageNode> children = new ArrayList<>();
93-
List<IPath> paths = Arrays.asList(workspacePath);
9492
for (IProject project : projects) {
95-
if (!ProjectUtils.isJavaProject(project)) {
93+
if (!project.isAccessible() || !ProjectUtils.isJavaProject(project) || Objects.equals(project, JavaLanguageServerPlugin.getProjectsManager().getDefaultProject())) {
9694
continue;
9795
}
98-
if (project.exists() && (ResourceUtils.isContainedIn(project.getLocation(), paths) || Objects.equals(project.getName(), invisibleProjectName))) {
99-
PackageNode projectNode = PackageNode.createNodeForProject(JavaCore.create(project));
100-
children.add(projectNode);
96+
PackageNode projectNode = PackageNode.createNodeForProject(JavaCore.create(project));
97+
if (Objects.equals(project.getName(), invisibleProjectName)) {
98+
projectNode.setDisplayName(FilenameUtils.getBaseName(workspaceUri));
10199
}
100+
children.add(projectNode);
102101
}
103102
return children;
104103
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ public class PackageNode {
7373
*/
7474
private String name;
7575

76+
/**
77+
* The display name of the node
78+
*/
79+
private String displayName;
80+
7681
/**
7782
* The module name of the PackageNode for Java 9 and above
7883
*/
@@ -275,6 +280,10 @@ public String getName() {
275280
return name;
276281
}
277282

283+
public void setDisplayName(String displayName) {
284+
this.displayName = displayName;
285+
}
286+
278287
public void setModuleName(String moduleName) {
279288
this.moduleName = moduleName;
280289
}

src/java/nodeData.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export enum TypeKind {
1919
}
2020

2121
export interface INodeData {
22+
displayName?: string;
2223
name: string;
2324
moduleName?: string;
2425
path?: string;

src/views/dataNode.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ export abstract class DataNode extends ExplorerNode {
1313

1414
public getTreeItem(): TreeItem | Promise<TreeItem> {
1515
if (this._nodeData) {
16-
const item = new TreeItem(this._nodeData.name, this.hasChildren() ? TreeItemCollapsibleState.Collapsed : TreeItemCollapsibleState.None);
16+
const item = new TreeItem(
17+
this._nodeData.displayName || this._nodeData.name,
18+
this.hasChildren() ? TreeItemCollapsibleState.Collapsed : TreeItemCollapsibleState.None,
19+
);
1720
item.description = this.description;
1821
item.iconPath = this.iconPath;
1922
item.command = this.command;

0 commit comments

Comments
 (0)